Add features (incomplete, highly experimental), fix DundiLookup app, debug improvemen...
[asterisk/asterisk.git] / logger.c
index 683c186..7f32b70 100755 (executable)
--- a/logger.c
+++ b/logger.c
@@ -48,10 +48,18 @@ static int syslog_level_map[] = {
 
 #define MAX_MSG_QUEUE 200
 
+#ifdef __linux__
+#include <asm/unistd.h>
+#define GETTID() syscall(__NR_gettid)
+#else
+#define GETTID() getpid()
+#endif
+
 static char dateformat[256] = "%b %e %T";              /* Original Asterisk Format */
 AST_MUTEX_DEFINE_STATIC(msglist_lock);
 AST_MUTEX_DEFINE_STATIC(loglock);
 static int pending_logger_reload = 0;
+static int global_logmask = -1;
 
 static struct msglist {
        char *msg;
@@ -211,6 +219,7 @@ static void init_logger_chain(void)
        logchannels = NULL;
        ast_mutex_unlock(&loglock);
        
+       global_logmask = 0;
        /* close syslog */
        closelog();
        
@@ -241,6 +250,7 @@ static void init_logger_chain(void)
                if (chan) {
                        chan->next = logchannels;
                        logchannels = chan;
+                       global_logmask |= chan->logmask;
                }
                var = var->next;
        }
@@ -481,11 +491,11 @@ static void ast_log_vsyslog(int level, const char *file, int line, const char *f
                return;
        }
        if (level == __LOG_VERBOSE) {
-               snprintf(buf, sizeof(buf), "VERBOSE[%ld]: ", (long)pthread_self());
+               snprintf(buf, sizeof(buf), "VERBOSE[%ld]: ", (long)GETTID());
                level = __LOG_DEBUG;
        } else {
                snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ",
-                       levels[level], (long)pthread_self(), file, line, function);
+                       levels[level], (long)GETTID(), file, line, function);
        }
        vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, args);
        syslog(syslog_level_map[level], "%s", buf);
@@ -507,6 +517,9 @@ void ast_log(int level, const char *file, int line, const char *function, const
        if (!option_verbose && !option_debug && (level == __LOG_DEBUG)) {
                return;
        }
+       /* Ignore anything that never gets logged anywhere */
+       if (!(global_logmask & (1 << level)))
+               return;
 
        /* begin critical section */
        ast_mutex_lock(&loglock);
@@ -543,7 +556,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
                                        snprintf(buf, sizeof(buf), "%s %s[%ld]: %s:%s %s: ",
                                                date,
                                                term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
-                                               (long)pthread_self(),
+                                               (long)GETTID(),
                                                term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
                                                term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
                                                term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
@@ -556,7 +569,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
                                }
                        } else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
                                snprintf(buf, sizeof(buf), "%s %s[%ld]: ", date,
-                                       levels[level], (long)pthread_self());
+                                       levels[level], (long)GETTID());
                                fprintf(chan->fileptr, buf);
                                va_start(ap, fmt);
                                vsnprintf(buf, sizeof(buf), fmt, ap);