Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Log.cpp: Use raw_ostream and llvm path functions. (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored Aug 27, 2017
1 parent baa8021 commit 12b2efa
Showing 1 changed file with 10 additions and 36 deletions.
46 changes: 10 additions & 36 deletions src/main/native/cpp/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,9 @@

#include "Log.h"

#include <cstdio>
#ifdef _WIN32
#include <cstdlib>
#else
#include <cstring>
#endif

#ifdef __APPLE__
#include <libgen.h>
#endif

#ifdef __ANDROID__
#include <libgen.h>
#endif
#include "llvm/Path.h"
#include "llvm/StringRef.h"
#include "llvm/raw_ostream.h"

using namespace nt;

Expand All @@ -29,36 +18,21 @@ ATOMIC_STATIC_INIT(Logger)
static void def_log_func(unsigned int level, const char* file,
unsigned int line, const char* msg) {
if (level == 20) {
std::fprintf(stderr, "NT: %s\n", msg);
llvm::errs() << "NT: " << msg << '\n';
return;
}

const char* levelmsg;
llvm::StringRef levelmsg;
if (level >= 50)
levelmsg = "CRITICAL";
levelmsg = "CRITICAL: ";
else if (level >= 40)
levelmsg = "ERROR";
levelmsg = "ERROR: ";
else if (level >= 30)
levelmsg = "WARNING";
levelmsg = "WARNING: ";
else
return;
#ifdef _WIN32
char fname[60];
char ext[10];
_splitpath_s(file, nullptr, 0, nullptr, 0, fname, 60, ext, 10);
std::fprintf(stderr, "NT: %s: %s (%s%s:%d)\n", levelmsg, msg, fname, ext,
line);
#elif __APPLE__
int len = strlen(msg) + 1;
char* basestr = new char[len + 1];
strncpy(basestr, file, len);
std::fprintf(stderr, "NT: %s: %s (%s:%d)\n", levelmsg, msg, basename(basestr),
line);
delete[] basestr;
#else
std::fprintf(stderr, "NT: %s: %s (%s:%d)\n", levelmsg, msg, basename(file),
line);
#endif
llvm::errs() << "NT: " << levelmsg << msg << " ("
<< llvm::sys::path::filename(file) << ':' << line << ")\n";
}

Logger::Logger() { SetLogger(def_log_func); }
Expand Down

0 comments on commit 12b2efa

Please sign in to comment.