X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Flog.c;h=2ca25a4d25955aee52e7fe5f7375cf39231115ce;hp=1999b17f1ea3e6cd60311169bec529feeff15cfa;hb=ede90e3f60487332bcaede6d8f62ad0f3e0fb715;hpb=3da21ae4ccca49971551bcd90e0b30bfcd827708 diff --git a/lib/log.c b/lib/log.c index 1999b17..2ca25a4 100644 --- a/lib/log.c +++ b/lib/log.c @@ -6,12 +6,23 @@ Copyright (c) 2001 Matthias Kramm - This file is distributed under the GPL, see file COPYING for details */ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + 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 #if _MSC_VER > 1000 @@ -27,119 +38,38 @@ #include "log.h" -#define LOGLEVEL_FATAL 0 -#define LOGLEVEL_ERROR 1 -#define LOGLEVEL_WARNING 2 -#define LOGLEVEL_NOTICE 3 -#define LOGLEVEL_VERBOSE 4 -#define LOGLEVEL_DEBUG 5 - -int screenloglevel; -int fileloglevel; -int socketloglevel; -FILE *logFile = 0; -#ifdef __NT__ -SOCKET logSocket; -#else -int logSocket = 0; -#endif - -char bLogToSock = 0; - -void initlogSocket(char* servAddr, char* logPort); +int screenloglevel = 1; +static int fileloglevel = -1; +static int maxloglevel = 1; +static FILE *logFile = 0; -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; - logFile = NULL; - bLogToSock = 0; - - if (pLogName && fileloglevel>=0) - logFile = fopen(pLogName, "a+"); - bLogToSock = (servAddr && logPort && (serverlevel>=0)); - if(bLogToSock) - initlogSocket(servAddr, logPort); -} - -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; + maxloglevel=screenloglevel; + if(fileloglevel>maxloglevel && pLogName) + maxloglevel=fileloglevel; - 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; - } + logFile = NULL; - // try to connect to the specified socket - if ( connect(logSocket, (struct sockaddr*)&SocketAddress, sizeof (SocketAddress)) == SOCKET_ERROR) { - bLogToSock = false; - return; - } - bLogToSock = true; -#endif + if (pLogName && fileloglevel>=0) + 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 "}; -void log(char* logString) +static inline void log(char* logString) { char timebuffer[32]; char* logBuffer; @@ -223,28 +153,24 @@ 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); } -void logf(const char* format, ...) +void msg(const char* format, ...) { char buf[1024]; va_list arglist; va_start(arglist, format); - buf[0] = 0; - vsprintf(&buf[strlen(buf)], format, arglist); + + /* speed up hack */ + if(format[0]=='<') { + char*z = "fewnvdt"; + char*x = strchr(z,format[1]); + if(x && (x-z)>maxloglevel) + return; + } + + vsprintf(buf, format, arglist); va_end(arglist); strcat(buf, "\n"); log(buf);