1 /***************************************************************************
2 Log.c - utilities
3 -------------------
4 begin : Sun Dec 29 2002
5 copyright : (C) 2002 by Proxy Labs (www.proxylabs.com)
6 email : yaph@proxylabs.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "yaph.h"
19
20 #define LOG_BUFF 1024*20
21
write_log(int level,char * file,char * func,int line,char * str,...)22 int write_log(int level,char* file, char* func, int line,char *str,...)
23 {
24 char buff[LOG_BUFF];
25 char d_stamp[100];
26 struct tm tm;
27 time_t t;
28 va_list arglist;
29 FILE * log_file;
30 log_file=globals->log_file_f;
31 if (level<=globals->debug_level)
32 {
33 va_start(arglist,str);
34 vsprintf(buff,str,arglist);
35 va_end(arglist);
36 t=time(NULL);
37 localtime_r(&t,&tm);
38 strftime(d_stamp,99,"%a %d/%b %H:%M:%S",&tm);
39 fprintf(log_file,"[%s]:PID=%d:%s:%s:%d: %s\n",d_stamp,getpid(),file,func,line,buff);
40 fflush(log_file);
41 }
42
43 return EXIT_SUCCESS;
44 }
45
46