Changeset 2159
- Timestamp:
- Jul 19, 2008 5:53:47 PM (16 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/log.h
r2039 r2159 69 69 enum pj_log_decoration 70 70 { 71 PJ_LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no]. */ 72 PJ_LOG_HAS_YEAR = 2, /**< Include year digit [default: no] */ 73 PJ_LOG_HAS_MONTH = 4, /**< Include month [default: no] */ 74 PJ_LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [default: no] */ 75 PJ_LOG_HAS_TIME = 16, /**< Include time [default: yes]. */ 76 PJ_LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */ 77 PJ_LOG_HAS_SENDER = 64, /**< Include sender in the log [yes]. */ 78 PJ_LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes].*/ 79 PJ_LOG_HAS_CR = 256 /**< Include carriage return [no]. */ 71 PJ_LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no] */ 72 PJ_LOG_HAS_YEAR = 2, /**< Include year digit [no] */ 73 PJ_LOG_HAS_MONTH = 4, /**< Include month [no] */ 74 PJ_LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [no] */ 75 PJ_LOG_HAS_TIME = 16, /**< Include time [yes] */ 76 PJ_LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */ 77 PJ_LOG_HAS_SENDER = 64, /**< Include sender in the log [yes] */ 78 PJ_LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes] */ 79 PJ_LOG_HAS_CR = 256, /**< Include carriage return [no] */ 80 PJ_LOG_HAS_SPACE = 512, /**< Include two spaces before log [yes] */ 81 PJ_LOG_HAS_COLOR = 1024 /**< Colorize logs [yes on win32] */ 80 82 }; 81 83 … … 200 202 201 203 204 /** 205 * Set color of log messages. 206 * 207 * @param level Log level which color will be changed. 208 * @param color Desired color. 209 */ 210 PJ_DECL(void) pj_log_set_color(int level, pj_color_t color); 211 212 /** 213 * Get color of log messages. 214 * 215 * @param level Log level which color will be returned. 216 * @return Log color. 217 */ 218 PJ_DECL(pj_color_t) pj_log_get_color(int level); 219 220 202 221 #else /* #if PJ_LOG_MAX_LEVEL >= 1 */ 203 222 … … 237 256 238 257 /** 258 * Set color of log messages. 259 * 260 * @param level Log level which color will be changed. 261 * @param color Desired color. 262 */ 263 # define pj_log_set_color(level, color) 264 265 /** 239 266 * Get current maximum log verbositylevel. 240 267 * … … 249 276 */ 250 277 # define pj_log_get_decor() 0 278 279 /** 280 * Get color of log messages. 281 * 282 * @param level Log level which color will be returned. 283 * @return Log color. 284 */ 285 # define pj_log_get_color(level) 0 251 286 252 287 -
pjproject/trunk/pjlib/src/pj/log.c
r2039 r2159 32 32 static pj_log_func *log_writer = &pj_log_write; 33 33 static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC | 34 PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE; 34 PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE | 35 PJ_LOG_HAS_SPACE 36 #if defined(PJ_WIN32) && PJ_WIN32!=0 37 | PJ_LOG_HAS_COLOR 38 #endif 39 ; 40 41 static pj_color_t PJ_LOG_COLOR_0 = PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R; 42 static pj_color_t PJ_LOG_COLOR_1 = PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R; 43 static pj_color_t PJ_LOG_COLOR_2 = PJ_TERM_COLOR_BRIGHT | 44 PJ_TERM_COLOR_R | 45 PJ_TERM_COLOR_G; 46 static pj_color_t PJ_LOG_COLOR_3 = PJ_TERM_COLOR_BRIGHT | 47 PJ_TERM_COLOR_R | 48 PJ_TERM_COLOR_G | 49 PJ_TERM_COLOR_B; 50 static pj_color_t PJ_LOG_COLOR_4 = PJ_TERM_COLOR_R | 51 PJ_TERM_COLOR_G | 52 PJ_TERM_COLOR_B; 53 static pj_color_t PJ_LOG_COLOR_5 = PJ_TERM_COLOR_R | 54 PJ_TERM_COLOR_G | 55 PJ_TERM_COLOR_B; 56 static pj_color_t PJ_LOG_COLOR_6 = PJ_TERM_COLOR_R | 57 PJ_TERM_COLOR_G | 58 PJ_TERM_COLOR_B; 59 /* Default terminal color */ 60 static pj_color_t PJ_LOG_COLOR_77 = PJ_TERM_COLOR_R | 61 PJ_TERM_COLOR_G | 62 PJ_TERM_COLOR_B; 35 63 36 64 #if PJ_LOG_USE_STACK_BUFFER==0 … … 46 74 { 47 75 return log_decor; 76 } 77 78 PJ_DEF(void) pj_log_set_color(int level, pj_color_t color) 79 { 80 switch (level) 81 { 82 case 0: PJ_LOG_COLOR_0 = color; 83 break; 84 case 1: PJ_LOG_COLOR_1 = color; 85 break; 86 case 2: PJ_LOG_COLOR_2 = color; 87 break; 88 case 3: PJ_LOG_COLOR_3 = color; 89 break; 90 case 4: PJ_LOG_COLOR_4 = color; 91 break; 92 case 5: PJ_LOG_COLOR_5 = color; 93 break; 94 case 6: PJ_LOG_COLOR_6 = color; 95 break; 96 /* Default terminal color */ 97 case 77: PJ_LOG_COLOR_77 = color; 98 break; 99 default: 100 /* Do nothing */ 101 break; 102 } 103 } 104 105 PJ_DEF(pj_color_t) pj_log_get_color(int level) 106 { 107 switch (level) { 108 case 0: 109 return PJ_LOG_COLOR_0; 110 case 1: 111 return PJ_LOG_COLOR_1; 112 case 2: 113 return PJ_LOG_COLOR_2; 114 case 3: 115 return PJ_LOG_COLOR_3; 116 case 4: 117 return PJ_LOG_COLOR_4; 118 case 5: 119 return PJ_LOG_COLOR_5; 120 case 6: 121 return PJ_LOG_COLOR_6; 122 default: 123 /* Return default terminal color */ 124 return PJ_LOG_COLOR_77; 125 } 48 126 } 49 127 … … 106 184 } 107 185 if (log_decor & PJ_LOG_HAS_DAY_OF_MON) { 108 *pre++ = ' 186 *pre++ = '-'; 109 187 pre += pj_utoa_pad(ptime.day, pre, 2, '0'); 110 188 } … … 140 218 *pre++ = ' '; 141 219 220 if (log_decor & PJ_LOG_HAS_SPACE) { 221 *pre++ = ' '; 222 } 223 142 224 len = pre - log_buffer; 143 225 -
pjproject/trunk/pjlib/src/pj/log_writer_stdout.c
r2039 r2159 21 21 #include <pj/compat/stdfileio.h> 22 22 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)28 23 29 24 static void term_set_color(int level) 30 25 { 31 26 #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)); 47 28 #endif 48 29 } … … 51 32 { 52 33 #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)); 54 36 #endif 55 37 } … … 62 44 63 45 /* 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 } 67 53 } 68 54 -
pjproject/trunk/pjlib/src/pj/os_core_unix.c
r2039 r2159 1690 1690 PJ_DEF(pj_status_t) pj_term_set_color(pj_color_t color) 1691 1691 { 1692 PJ_UNUSED_ARG(color); 1693 return PJ_EINVALIDOP; 1692 /* put bright prefix to ansi_color */ 1693 char ansi_color[12] = "\033[01;3"; 1694 1695 if (color & PJ_TERM_COLOR_BRIGHT) { 1696 color ^= PJ_TERM_COLOR_BRIGHT; 1697 } else { 1698 strcpy(ansi_color, "\033[00;3"); 1699 } 1700 1701 switch (color) { 1702 case 0: 1703 /* black color */ 1704 strcat(ansi_color, "0m"); 1705 break; 1706 case PJ_TERM_COLOR_R: 1707 /* red color */ 1708 strcat(ansi_color, "1m"); 1709 break; 1710 case PJ_TERM_COLOR_G: 1711 /* green color */ 1712 strcat(ansi_color, "2m"); 1713 break; 1714 case PJ_TERM_COLOR_B: 1715 /* blue color */ 1716 strcat(ansi_color, "4m"); 1717 break; 1718 case PJ_TERM_COLOR_R | PJ_TERM_COLOR_G: 1719 /* yellow color */ 1720 strcat(ansi_color, "3m"); 1721 break; 1722 case PJ_TERM_COLOR_R | PJ_TERM_COLOR_B: 1723 /* magenta color */ 1724 strcat(ansi_color, "5m"); 1725 break; 1726 case PJ_TERM_COLOR_G | PJ_TERM_COLOR_B: 1727 /* cyan color */ 1728 strcat(ansi_color, "6m"); 1729 break; 1730 case PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | PJ_TERM_COLOR_B: 1731 /* white color */ 1732 strcat(ansi_color, "7m"); 1733 break; 1734 default: 1735 /* default console color */ 1736 strcpy(ansi_color, "\033[00m"); 1737 break; 1738 } 1739 1740 fputs(ansi_color, stdout); 1741 1742 return PJ_SUCCESS; 1694 1743 } 1695 1744 -
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r2154 r2159 159 159 puts (" --log-level=N Set log max level to N (0(none) to 6(trace)) (default=5)"); 160 160 puts (" --app-log-level=N Set log max level for stdout display (default=4)"); 161 puts (" --color Use colorful logging (default yes on Win32)"); 162 puts (" --no-color Disable colorful logging"); 163 161 164 puts (""); 162 165 puts ("SIP Account options:"); … … 443 446 int option_index; 444 447 enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, 448 OPT_COLOR, OPT_NO_COLOR, 445 449 OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_SND_AUTO_CLOSE, 446 450 OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, … … 477 481 { "log-level", 1, 0, OPT_LOG_LEVEL}, 478 482 { "app-log-level",1,0,OPT_APP_LOG_LEVEL}, 483 { "color", 0, 0, OPT_COLOR}, 484 { "no-color", 0, 0, OPT_NO_COLOR}, 479 485 { "help", 0, 0, OPT_HELP}, 480 486 { "version", 0, 0, OPT_VERSION}, … … 638 644 break; 639 645 646 case OPT_COLOR: 647 cfg->log_cfg.decor |= PJ_LOG_HAS_COLOR; 648 break; 649 650 case OPT_NO_COLOR: 651 cfg->log_cfg.decor &= ~PJ_LOG_HAS_COLOR; 652 break; 653 640 654 case OPT_HELP: 641 655 usage(); … … 3757 3771 len = write_settings(&app_config, settings, sizeof(settings)); 3758 3772 if (len < 1) 3759 PJ_LOG( 3,(THIS_FILE, "Error: not enough buffer"));3773 PJ_LOG(1,(THIS_FILE, "Error: not enough buffer")); 3760 3774 else 3761 3775 PJ_LOG(3,(THIS_FILE, … … 3784 3798 len = write_settings(&app_config, settings, sizeof(settings)); 3785 3799 if (len < 1) 3786 PJ_LOG( 3,(THIS_FILE, "Error: not enough buffer"));3800 PJ_LOG(1,(THIS_FILE, "Error: not enough buffer")); 3787 3801 else { 3788 3802 pj_oshandle_t fd; … … 4082 4096 4083 4097 if (transport_id == -1) { 4084 PJ_LOG( 3,(THIS_FILE, "Error: no transport is configured"));4098 PJ_LOG(1,(THIS_FILE, "Error: no transport is configured")); 4085 4099 status = -1; 4086 4100 goto on_error; -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r2157 r2159 41 41 42 42 pj_strerror(status, errmsg, sizeof(errmsg)); 43 PJ_LOG( 3,(sender, "%s: %s [status=%d]", title, errmsg, status));43 PJ_LOG(1,(sender, "%s: %s [status=%d]", title, errmsg, status)); 44 44 } 45 45 … … 70 70 cfg->console_level = 4; 71 71 cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME | 72 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE; 72 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE | 73 PJ_LOG_HAS_SPACE; 74 #if defined(PJ_WIN32) && PJ_WIN32 != 0 75 cfg->decor |= PJ_LOG_HAS_COLOR; 76 #endif 73 77 } 74 78
Note: See TracChangeset
for help on using the changeset viewer.