From 182a15ca19841f241f35e491965a32a51598fc49 Mon Sep 17 00:00:00 2001 From: kramm Date: Fri, 22 Oct 2004 15:06:09 +0000 Subject: [PATCH] several cleanups. --- lib/log.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++--------------- lib/log.h | 12 +++++------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/lib/log.c b/lib/log.c index 2ca25a4..d835836 100644 --- a/lib/log.c +++ b/lib/log.c @@ -38,38 +38,61 @@ #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; +} - 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 fileloglevel, char* s00, char* s01, int s02, int screenlevel) +{ + setFileLogging(filename, fileloglevel, 0); + setConsoleLogging(screenloglevel); } 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(const char* logString) { char timebuffer[32]; char* logBuffer; @@ -156,6 +179,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(buf); +} void msg(const char* format, ...) { char buf[1024]; diff --git a/lib/log.h b/lib/log.h index 6210150..9afa0f5 100644 --- a/lib/log.h +++ b/lib/log.h @@ -25,15 +25,9 @@ extern "C" { #endif -#ifdef __NT__ -#include "stdafx.h" -#include -#include -#else #include #include #include -#endif #define LOGLEVEL_FATAL 0 #define LOGLEVEL_ERROR 1 @@ -43,10 +37,14 @@ extern "C" { #define LOGLEVEL_DEBUG 5 #define LOGLEVEL_TRACE 6 -extern int screenloglevel; +extern int getScreenLogLevel(); extern void initLog(char* pLogDir, int fileloglevel, char* servAddr, char* logPort, int serverloglevel, int screenloglevel); +extern void setConsoleLogging(int level); +extern void setFileLogging(char*filename, int level, char append); + extern void msg(const char* logFormat, ...); +extern void msg_str(const char* log); extern void exitLog(void); #define FIXNULL(a) ((int)(a)?(a):"NULL") -- 1.7.10.4