diff --git a/src/Client/log.cpp b/src/Client/log.cpp new file mode 100644 index 0000000..1dad83b --- /dev/null +++ b/src/Client/log.cpp @@ -0,0 +1,84 @@ +#include +#include "common.h" +#include "PseuWoW.h" +#include "log.h" + +PseuInstance *instance=NULL; +FILE *logfile=NULL; + + +void log_prepare(char *fn, PseuInstance* p) +{ + logfile = fopen(fn,"a"); + instance = p; +} + +void log(const char *str, ...) +{ + if(!str) + return; + va_list ap; + va_start(ap, str); + vprintf( str, ap ); + va_end(ap); + + printf("\n"); + + if(logfile) + { + fprintf(logfile, getDateString().c_str()); + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } + fflush(stdout); +} + +void logdetail(const char *str, ...) +{ + if(!str || instance->GetConf()->debug < 1) + return; + va_list ap; + va_start(ap, str); + vprintf( str, ap ); + va_end(ap); + + printf("\n"); + + if(logfile) + { + fprintf(logfile, getDateString().c_str()); + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } + fflush(stdout); +} + +void logdebug(const char *str, ...) +{ + if(!str || instance->GetConf()->debug < 2) + return; + va_list ap; + va_start(ap, str); + vprintf( str, ap ); + va_end(ap); + + printf("\n"); + + if(logfile) + { + fprintf(logfile, getDateString().c_str()); + va_start(ap, str); + vfprintf(logfile, str, ap); + fprintf(logfile, "\n" ); + va_end(ap); + fflush(logfile); + } + fflush(stdout); +} + \ No newline at end of file diff --git a/src/Client/log.h b/src/Client/log.h new file mode 100644 index 0000000..7354fca --- /dev/null +++ b/src/Client/log.h @@ -0,0 +1,12 @@ +#ifndef _LOG_H +#define _LOG_H + +class PseuInstance; + +void log_prepare(char *fn, PseuInstance* p); +void log(const char *str, ...); +void logdetail(const char *str, ...); +void logdebug(const char *str, ...); + +#endif + \ No newline at end of file