-int verbosity = DEFAULT_VERBOSITY; /* Logging level */
-
-int syslog_facility = LOG_DAEMON;
-int enable_syslog = 0;
-int print_to_logfile = 1;
-
-/*
- * CtdlLogPrintf() ... Write logging information
- */
-void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...) {
- va_list arg_ptr;
- va_start(arg_ptr, format);
- vCtdlLogPrintf(loglevel, format, arg_ptr);
- va_end(arg_ptr);
-}
-
-void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
-{
-
- if (enable_syslog) {
- vsyslog((syslog_facility | loglevel), format, arg_ptr);
- }
-
- /* stderr output code */
- if (enable_syslog || !print_to_logfile) return;
-
- /* if we run in forground and syslog is disabled, log to terminal */
- if (loglevel <= verbosity) {
- struct timeval tv;
- struct tm tim;
- time_t unixtime;
- CitContext *CCC = CC;
- ThreadTSD *cTSD = CTP;
- CtdlThreadNode *node = NULL;
- long lwpid = 0;
- char formatbuf[SIZ];
- char LWP[64];
- char SESS[64];
-
- if (cTSD != NULL) {
- node = cTSD->self;
- }
-
- if ((node != NULL) && (node->reltid != 0)) {
- lwpid = node->reltid;
- }
-
- gettimeofday(&tv, NULL);
-
- /* Promote to time_t; types differ on some OSes (like darwin) */
- unixtime = tv.tv_sec;
- localtime_r(&unixtime, &tim);
-
- *LWP = '\0';
- if (lwpid != 0) {
- snprintf(LWP, 64, "[LWP:%ld] ", lwpid);
- }
-
- *SESS = '\0';
- if (CCC != NULL) {
- if (CCC->cs_pid != 0) {
- snprintf(SESS, 64, " [%3d] ", CCC->cs_pid);
- }
- else if (CCC->user.usernum != 0) {
- snprintf(SESS, 64, " [:%ld] ", CCC->user.usernum);
- }
- }
-
- snprintf(formatbuf, SIZ,
- "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s%s%s",
- tim.tm_year + 1900, tim.tm_mon + 1,
- tim.tm_mday, tim.tm_hour, tim.tm_min,
- tim.tm_sec, (long)tv.tv_usec,
- LWP, SESS, format
- );
-
- vfprintf(stderr, formatbuf, arg_ptr);
- fflush(stderr);
- }
-}
-
-
-