From f69f5aa358821e4b94646d1482e6f03239b5c67a Mon Sep 17 00:00:00 2001 From: kramm Date: Mon, 17 Nov 2003 19:57:58 +0000 Subject: [PATCH] added "TRACE" debuglevel, removed socket logging code. --- lib/log.c | 112 ++++--------------------------------------------------------- lib/log.h | 1 + 2 files changed, 7 insertions(+), 106 deletions(-) diff --git a/lib/log.c b/lib/log.c index 9c7c228..2ca25a4 100644 --- a/lib/log.c +++ b/lib/log.c @@ -23,7 +23,6 @@ #ifdef __NT__ #include "stdafx.h" #include -#include #include #include #if _MSC_VER > 1000 @@ -41,122 +40,35 @@ int screenloglevel = 1; static int fileloglevel = -1; -static int socketloglevel = -1; static int maxloglevel = 1; static FILE *logFile = 0; -#ifdef __NT__ -static SOCKET logSocket; -#else -static int logSocket = 0; -#endif - -static char bLogToSock = 0; - -static void initlogSocket(char* servAddr, char* logPort); -void initLog(char* pLogName, int fileloglevel, char* servAddr, char* logPort, int serverlevel, int screenlevel) +void initLog(char* pLogName, int fileloglevel, char* s00, char* s01, int s02, int screenlevel) { screenloglevel = screenlevel; fileloglevel = fileloglevel; - socketloglevel = screenlevel; maxloglevel=screenloglevel; if(fileloglevel>maxloglevel && pLogName) maxloglevel=fileloglevel; - if(serverlevel>maxloglevel && servAddr) - maxloglevel=serverlevel; - - if(!servAddr) - serverlevel = -1; - if(!pLogName) - fileloglevel = -1; logFile = NULL; - bLogToSock = 0; if (pLogName && fileloglevel>=0) - logFile = fopen(pLogName, "a+"); - bLogToSock = (servAddr && logPort && (serverlevel>=0)); - if(bLogToSock) - initlogSocket(servAddr, logPort); -} - -static void initlogSocket(char* servAddr, char* logPort) -{ -#ifndef __NT__ - bLogToSock = 0; -#else - // init winsock - // check and prepare WinSock DLL - WORD wVersionRequested = MAKEWORD( 2, 2 ); - WSADATA wsaData; - if ( WSAStartup(wVersionRequested, &wsaData) != 0 ) - { - bLogToSock = false; - return; - } - // Confirm that the WinSock DLL supports 2.2. - // Note that if the DLL supports versions greater - // than 2.2 in addition to 2.2, it will still return - // 2.2 in wVersion since that is the version we - // requested. - - if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) - { - bLogToSock = false; - return; - } - - struct hostent *hp; - hp = gethostbyname(servAddr); - if (hp == NULL) // we don't know who this host is - { - bLogToSock = false; - return; - } - - // connect socket - sockaddr_in SocketAddress; - - memset(&SocketAddress, 0, sizeof(SocketAddress)); - memcpy((char*)&SocketAddress.sin_addr, hp->h_addr, hp->h_length); // set address - SocketAddress.sin_family = hp->h_addrtype; - SocketAddress.sin_port = htons((u_short)atoi(logPort)); - - logSocket = socket(hp->h_addrtype, SOCK_STREAM, 0); - if (logSocket == INVALID_SOCKET) - { - bLogToSock = false; - return; - } - - // try to connect to the specified socket - if ( connect(logSocket, (struct sockaddr*)&SocketAddress, sizeof (SocketAddress)) == SOCKET_ERROR) { - bLogToSock = false; - return; - } - bLogToSock = true; -#endif + logFile = fopen(pLogName, "a+"); } void exitLog() { - // close socket communication - if(bLogToSock) -#ifndef __NT__ - close(logSocket); -#else - closesocket(logSocket); -#endif // close file if(logFile != NULL) fclose(logFile); } +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 char * logimportance[]= {"Fatal","Error","Warning","Notice","Verbose","Debug"}; -static int loglevels=6; -static char * logimportance2[]= {" ","FATAL ","ERROR ","WARNING","NOTICE ","VERBOSE","DEBUG "}; static inline void log(char* logString) { char timebuffer[32]; @@ -241,18 +153,6 @@ static inline void log(char* logString) } } - if (level <= socketloglevel) - { - if (bLogToSock) - { - // send data -#ifndef __NT__ - write(logSocket, logBuffer, strlen(logBuffer)); -#else - send(logSocket, logBuffer, strlen(logBuffer), 0); -#endif - } - } free (logBuffer); } @@ -264,7 +164,7 @@ void msg(const char* format, ...) /* speed up hack */ if(format[0]=='<') { - char*z = "fewnvd"; + char*z = "fewnvdt"; char*x = strchr(z,format[1]); if(x && (x-z)>maxloglevel) return; diff --git a/lib/log.h b/lib/log.h index 38ac423..6210150 100644 --- a/lib/log.h +++ b/lib/log.h @@ -41,6 +41,7 @@ extern "C" { #define LOGLEVEL_NOTICE 3 #define LOGLEVEL_VERBOSE 4 #define LOGLEVEL_DEBUG 5 +#define LOGLEVEL_TRACE 6 extern int screenloglevel; -- 1.7.10.4