]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
merge kevin's patches to remove color escape sequences from the logs (bug #3929)
authorRussell Bryant <russell@russellbryant.com>
Tue, 5 Apr 2005 06:09:27 +0000 (06:09 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 5 Apr 2005 06:09:27 +0000 (06:09 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@5394 65c4cc65-6c06-0410-ace0-fbb531ad65f3

CHANGES
logger.c

diff --git a/CHANGES b/CHANGES
index 6bfddef57a387065e09451b704c437d17eb58bd8..1bb2c48681af143e259d73fcbc24151bb65cff05 100755 (executable)
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,7 @@
        in some media players
     -- Fixed if the last line of text in a file for the call spool did not contain
        a new line, it would not be processed
+    -- Fixed the logger so that color escape sequences wouldn't be sent to the logs
 
 Asterisk 1.0.7
 
index cafe4d70dba374fbd8062f39cddbaeb9d88bc32b..a8c0c0dbfc3a404bec78745cdd9def1039aa684f 100755 (executable)
--- a/logger.c
+++ b/logger.c
@@ -478,9 +478,39 @@ void close_logger(void)
        return;
 }
 
+static void strip_coloring(char *str)
+{
+       char *src, *dest, *end;
+       
+       if (!str)
+               return;
+
+       /* find the first potential escape sequence in the string */
+
+       src = strchr(str, '\033');
+       if (!src)
+               return;
+
+       dest = src;
+       while (*src) {
+               /* at the top of this loop, *src will always be an ESC character */
+               if ((src[1] == '[') && ((end = strchr(src + 2, 'm'))))
+                       src = end + 1;
+               else
+                       *dest++ = *src++;
+
+               /* copy characters, checking for ESC as we go */
+               while (*src && (*src != '\033'))
+                       *dest++ = *src++;
+       }
+
+       *dest = '\0';
+}
+
 static void ast_log_vsyslog(int level, const char *file, int line, const char *function, const char *fmt, va_list args) 
 {
        char buf[BUFSIZ];
+       char *s;
 
        if (level >= SYSLOG_NLEVELS) {
                /* we are locked here, so cannot ast_log() */
@@ -492,9 +522,11 @@ static void ast_log_vsyslog(int level, const char *file, int line, const char *f
                level = __LOG_DEBUG;
        } else {
                snprintf(buf, sizeof(buf), "%s[%ld]: %s:%d in %s: ",
-                       levels[level], (long)GETTID(), file, line, function);
+                        levels[level], (long)GETTID(), file, line, function);
        }
-       vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, args);
+       s = buf + strlen(buf);
+       vsnprintf(s, sizeof(buf) - strlen(buf), fmt, args);
+       strip_coloring(s);
        syslog(syslog_level_map[level], "%s", buf);
 }
 
@@ -567,6 +599,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
                                fprintf(chan->fileptr, buf);
                                va_start(ap, fmt);
                                vsnprintf(buf, sizeof(buf), fmt, ap);
+                               strip_coloring(buf);    
                                va_end(ap);
                                fputs(buf, chan->fileptr);
                                fflush(chan->fileptr);