Ignore:
Timestamp:
Jul 19, 2008 5:53:47 PM (16 years ago)
Author:
bennylp
Message:

Ticket #571: Coloring for logs in Linux/UNIX, two more spaces in logs and runtime log colors configuration (thanks Ondrej.Sterbak)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/log_writer_stdout.c

    r2039 r2159  
    2121#include <pj/compat/stdfileio.h> 
    2222 
    23 #define CLR_FATAL    (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R) 
    24 #define CLR_WARNING  (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R | PJ_TERM_COLOR_G) 
    25 #define CLR_INFO     (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | \ 
    26                       PJ_TERM_COLOR_B) 
    27 #define CLR_DEFAULT  (PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | PJ_TERM_COLOR_B) 
    2823 
    2924static void term_set_color(int level) 
    3025{ 
    3126#if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0 
    32     unsigned attr = 0; 
    33     switch (level) { 
    34     case 0: 
    35     case 1: attr = CLR_FATAL;  
    36         break; 
    37     case 2: attr = CLR_WARNING;  
    38         break; 
    39     case 3: attr = CLR_INFO;  
    40         break; 
    41     default: 
    42         attr = CLR_DEFAULT; 
    43         break; 
    44     } 
    45  
    46     pj_term_set_color(attr); 
     27    pj_term_set_color(pj_log_get_color(level)); 
    4728#endif 
    4829} 
     
    5132{ 
    5233#if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0 
    53     pj_term_set_color(CLR_DEFAULT); 
     34    /* Set terminal to its default color */ 
     35    pj_term_set_color(pj_log_get_color(77)); 
    5436#endif 
    5537} 
     
    6244 
    6345    /* Copy to terminal/file. */ 
    64     term_set_color(level); 
    65     printf("%s", buffer); 
    66     term_restore_color(); 
     46    if (pj_log_get_decor() & PJ_LOG_HAS_COLOR) { 
     47        term_set_color(level); 
     48        printf("%s", buffer); 
     49        term_restore_color(); 
     50    } else { 
     51        printf("%s", buffer); 
     52    } 
    6753} 
    6854 
Note: See TracChangeset for help on using the changeset viewer.