void vwrite_log(const char *str, int dbg) { char timedstr[LARGE_STRING + 5] = {0}; char newstr[LARGE_STRING + 5]; FILE *log_f; struct tm t; struct timeval tv; xstrcpy( newstr, str, LARGE_STRING ); IFPerl( perl_on_log( newstr )); gettimeofday( &tv, NULL ); memcpy( &t, localtime( &tv.tv_sec ), sizeof(struct tm)); #ifdef NEED_DEBUG if ( facilities_levels['G'] >= 1 ) snprintf( timedstr, LARGE_STRING, "%02d %3s %02d %02d:%02d:%02d.%03u %s[%ld]: %s", t.tm_mday, engms[t.tm_mon], t.tm_year%100, t.tm_hour, t.tm_min, t.tm_sec, (unsigned) ( tv.tv_usec / 1000 ), SS( log_tty ), (long) getpid(), newstr ); else #endif snprintf( timedstr, LARGE_STRING, "%02d %3s %02d %02d:%02d:%02d %s[%ld]: %s", t.tm_mday, engms[t.tm_mon], t.tm_year%100, t.tm_hour, t.tm_min, t.tm_sec, SS( log_tty ), (long) getpid(), newstr ); if ( log_callback && dbg ) log_callback( timedstr ); switch( log_type ) { case LT_STDERR: fprintf( stderr, "%s: %s\n", progname, timedstr ); break; case LT_LOGFILE: if ( log_name ) { if (( log_f = fopen( log_name, "a" )) != NULL ) { fprintf( log_f, "%s\n", timedstr ); fclose( log_f ); } } break; case LT_SYSLOG: syslog( syslog_priority, newstr ); break; } }
void vwrite_log(char *fmt, char *prefix,int dbg,va_list args) { FILE *log_f; struct tm *t; struct timeval tv; char str[LARGE_STRING]={0},*p=NULL; gettimeofday(&tv,NULL); t=localtime(&tv.tv_sec); strftime(str,20,"%d %b %y %H:%M:%S",t); #ifdef NEED_DEBUG if(facilities_levels['T']>=1) snprintf(str+18,LARGE_STRING-24,".%03u %s[%ld]: ",(unsigned)(tv.tv_usec/1000),SS(log_tty),(long)getpid()); else #endif snprintf(str+18,LARGE_STRING-18," %s[%ld]: ",SS(log_tty),(long)getpid()); p=str+strlen(str); if(prefix&&*prefix) { xstrcpy(p,prefix,p-(char*)str); p=str+strlen(str); } vsnprintf(p,LARGE_STRING-50,fmt,args); IFPerl(perl_on_log(str)); if(log_callback&&dbg)log_callback(str); switch(log_type) { case 0: fputs(p,stderr); fputc('\n',stderr); break; case 1: if(log_name) { if((log_f=fopen(log_name, "at"))!=NULL) { fputs(str,log_f);fputc('\n',log_f); fclose(log_f); } } break; case 2: syslog(syslog_priority,p); break; } }