several cleanups.
authorkramm <kramm>
Fri, 22 Oct 2004 15:06:09 +0000 (15:06 +0000)
committerkramm <kramm>
Fri, 22 Oct 2004 15:06:09 +0000 (15:06 +0000)
lib/log.c
lib/log.h

index 2ca25a4..d835836 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
 
 #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];
index 6210150..9afa0f5 100644 (file)
--- a/lib/log.h
+++ b/lib/log.h
 extern "C" {
 #endif
 
-#ifdef __NT__
-#include "stdafx.h"
-#include <time.h>
-#include <windef.h>
-#else
 #include <stdlib.h>
 #include <stdio.h>
 #include <time.h>
-#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")