/* * This routine adds the contents of a buffer to the log */ void addto_syslog(int level, char * buf) { char *prog; FILE *out_file = syslog_file; #if !defined(VMS) && !defined (SYS_VXWORKS) if (syslogit) syslog(level, "%s", buf); else #endif /* VMS && SYS_VXWORKS*/ { out_file = syslog_file ? syslog_file: level <= LOG_ERR ? stderr : stdout; /* syslog() provides the timestamp, so if we're not using syslog, we must provide it. */ prog = strrchr(progname, separator); if (prog == NULL) prog = progname; else prog++; (void) fprintf(out_file, "%s ", humanlogtime ()); (void) fprintf(out_file, "%s[%d]: %s", prog, (int)getpid(), buf); fflush (out_file); } #if DEBUG if (debug && out_file != stdout && out_file != stderr) printf("addto_syslog: %s\n", buf); #endif }
/* * This routine adds the contents of a buffer to the syslog or an * application-specific logfile. */ void addto_syslog( int level, const char * msg ) { static char * prevcall_progname; static char * prog; const char nl[] = "\n"; const char empty[] = ""; FILE * term_file; int log_to_term; int log_to_file; const char * nl_or_empty; const char * human_time; /* setup program basename static var prog if needed */ if (progname != prevcall_progname) { prevcall_progname = progname; prog = strrchr(progname, DIR_SEP); if (prog != NULL) prog++; else prog = progname; } log_to_term = msyslog_term; log_to_file = FALSE; #if !defined(VMS) && !defined(SYS_VXWORKS) if (syslogit) syslog(level, "%s", msg); else #endif if (syslog_file != NULL) log_to_file = TRUE; else log_to_term = TRUE; #if DEBUG if (debug > 0) log_to_term = TRUE; #endif if (!(log_to_file || log_to_term)) return; /* syslog() adds the timestamp, name, and pid */ human_time = humanlogtime(); /* syslog() adds trailing \n if not present */ if ('\n' != msg[strlen(msg) - 1]) nl_or_empty = nl; else nl_or_empty = empty; if (log_to_term) { term_file = (level <= LOG_ERR) ? stderr : stdout; fprintf(term_file, "%s %s[%d]: %s%s", human_time, prog, (int)getpid(), msg, nl_or_empty); fflush(term_file); } if (log_to_file) { fprintf(syslog_file, "%s %s[%d]: %s%s", human_time, prog, (int)getpid(), msg, nl_or_empty); fflush(syslog_file); } }