X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Flog.c;h=2ca25a4d25955aee52e7fe5f7375cf39231115ce;hp=ace2987c577e1556da501debc51b821963bbd8bf;hb=ede90e3f60487332bcaede6d8f62ad0f3e0fb715;hpb=e3355d3845678422c3a46741f7209f921c80cb70 diff --git a/lib/log.c b/lib/log.c index ace2987..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,124 +38,37 @@ #include "log.h" -static int screenloglevel = 1; +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]; @@ -229,22 +153,10 @@ 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); } -void logf(const char* format, ...) +void msg(const char* format, ...) { char buf[1024]; va_list arglist; @@ -252,7 +164,7 @@ void logf(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;