X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Flog.c;h=e75148f127fce4c13c7b6bcc4868f9b7bb2bcb7b;hp=2ca25a4d25955aee52e7fe5f7375cf39231115ce;hb=c63b2bf21dc1df9a736f0b4c08f6cba828cdab92;hpb=f69f5aa358821e4b94646d1482e6f03239b5c67a diff --git a/lib/log.c b/lib/log.c index 2ca25a4..e75148f 100644 --- a/lib/log.c +++ b/lib/log.c @@ -20,56 +20,81 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef __NT__ -#include "stdafx.h" -#include #include +#include +#include +#ifdef WIN32 +//#include "stdafx.h" #include #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #else #include -#include -#include -#include #include #endif #include "log.h" -int screenloglevel = 1; +static int screenloglevel = 1; static int fileloglevel = -1; -static int maxloglevel = 1; static FILE *logFile = 0; +static int maxloglevel = 1; -void initLog(char* pLogName, int fileloglevel, char* s00, char* s01, int s02, int screenlevel) +int getScreenLogLevel() { - screenloglevel = screenlevel; - fileloglevel = fileloglevel; - - maxloglevel=screenloglevel; - if(fileloglevel>maxloglevel && pLogName) - maxloglevel=fileloglevel; - - logFile = NULL; + return screenloglevel; +} +int getLogLevel() +{ + return maxloglevel; +} - if (pLogName && fileloglevel>=0) - logFile = fopen(pLogName, "a+"); +void setConsoleLogging(int level) +{ + if(level>maxloglevel) + maxloglevel=level; + screenloglevel = level; +} +void setFileLogging(char*filename, int level, char append) +{ + if(level>maxloglevel) + maxloglevel=level; + if(logFile) { + fclose(logFile);logFile=0; + } + if(filename && level>=0) { + logFile = fopen(filename, append?"ab+":"wb"); + fileloglevel = level; + } else { + logFile = 0; + fileloglevel = 0; + } +} +/* deprecated */ +void initLog(char* filename, int filelevel, char* s00, char* s01, int s02, int screenlevel) +{ + setFileLogging(filename, filelevel, 0); + setConsoleLogging(screenlevel); } void exitLog() { // close file - if(logFile != NULL) + if(logFile != NULL) { fclose(logFile); + logFile = 0; + fileloglevel = -1; + screenloglevel = 1; + maxloglevel = 1; + } } static char * logimportance[]= {"Fatal","Error","Warning","Notice","Verbose","Debug","Trace"}; static int loglevels=7; static char * logimportance2[]= {" ","FATAL ","ERROR ","WARNING","NOTICE ","VERBOSE","DEBUG ", "TRACE "}; -static inline void log(char* logString) +static inline void log_str(const char* logString) { char timebuffer[32]; char* logBuffer; @@ -148,7 +173,7 @@ static inline void log(char* logString) { if (logFile != NULL) { - fprintf(logFile, "%s\n", logBuffer); + fprintf(logFile, "%s\r\n", logBuffer); fflush(logFile); } } @@ -156,6 +181,16 @@ static inline void log(char* logString) free (logBuffer); } +void msg_str(const char* buf) +{ + if(buf[0]=='<') { + char*z = "fewnvdt"; + char*x = strchr(z,buf[1]); + if(x && (x-z)>maxloglevel) + return; + } + log_str(buf); +} void msg(const char* format, ...) { char buf[1024]; @@ -170,9 +205,9 @@ void msg(const char* format, ...) return; } - vsprintf(buf, format, arglist); + vsnprintf(buf, sizeof(buf)-1, format, arglist); va_end(arglist); strcat(buf, "\n"); - log(buf); + log_str(buf); }