28 #include "../adapters/filemanager.h"
35 mLog = std::shared_ptr<Log>(
this);
51 const char* pattern =
"Entropy-Piano-Tuner/";
52 int patternsize = strlen(pattern);
53 int len = strlen(filename);
56 const char *substring = strstr(filename, pattern);
57 if (substring != NULL) filename = substring + patternsize;
62 void Log::verbose(
const char *text,
int line,
const char *file,
const char *
function) {
65 mLog->impl_verbose(buffer);
69 void Log::debug(
const char *text,
int line,
const char *file,
const char *
function) {
72 mLog->impl_debug(buffer);
76 void Log::information(
const char *text,
int line,
const char *file,
const char *
function) {
79 mLog->impl_information(buffer);
83 void Log::warning(
const char *text,
int line,
const char *file,
const char *
function) {
86 mLog->impl_warning(buffer);
90 void Log::error(
const char *text,
int line,
const char *file,
const char *
function) {
92 snprintf(buffer,
ERROR_BUFFER_SIZE,
"%s (line %d in file %s in function %s)", text, line, file,
function);
93 mLog->impl_error(buffer);
98 std::cout <<
"Verbose: " << l << std::endl;
102 std::cout <<
"Debug: " << l << std::endl;
106 std::cout <<
"Information: " << l << std::endl;
110 std::cout <<
"Warning: " << l << std::endl;
114 std::cout <<
"Error: " << l << std::endl;
122 std::time_t t = std::time(0);
125 localtime_s(&now, &t);
127 now = *localtime(&t);
129 char tmdescr[20]={0};
130 const char fmt[]=
"%X";
131 strftime(tmdescr,
sizeof(tmdescr) - 1, fmt, &now);
155 mLogStream <<
"In file " <<
simplify(file) <<
" in function " <<
function <<
" at line " << line << std::endl;
158 mLogStream <<
"\t\t" << text << std::endl << std::endl;
static void error(const char *text, int line, const char *file, const char *function)
static void verbose(const char *text, int line, const char *file, const char *function)
static void information(const char *text, int line, const char *file, const char *function)
static FileManager & getSingleton()
FileManager::getSingleton: Get a reference to the singleton.
virtual void impl_error(const char *l)
virtual void impl_debug(const char *l)
#define ERROR_BUFFER_SIZE
static const char * simplify(const char *filename)
Log(bool useLogfile=true)
static void warning(const char *text, int line, const char *file, const char *function)
void writeToLogfile(ELevel level, const char *text, int line, const char *file, const char *function)
virtual void impl_verbose(const char *l)
static std::shared_ptr< Log > mLog
static const std::string LOG_NAME
virtual void impl_warning(const char *l)
virtual bool open(std::ifstream &stream, const std::string &absolute, std::ios_base::openmode mode=std::ios_base::in)
Open an input stream.
virtual void impl_information(const char *l)
static void debug(const char *text, int line, const char *file, const char *function)