Benny Prijono | 0a749f1 | 2005-10-31 21:02:30 +0000 | [diff] [blame^] | 1 | /* $Header: /pjproject-0.3/pjlib/src/pj/log_writer_stdout.c 5 10/14/05 12:26a Bennylp $ */
|
| 2 | /* $Log: /pjproject-0.3/pjlib/src/pj/log_writer_stdout.c $
|
| 3 | *
|
| 4 | * 5 10/14/05 12:26a Bennylp
|
| 5 | * Finished error code framework, some fixes in ioqueue, etc. Pretty
|
| 6 | * major.
|
| 7 | *
|
| 8 | * 4 9/21/05 1:39p Bennylp
|
| 9 | * Periodic checkin for backup.
|
| 10 | *
|
| 11 | * 3 9/17/05 10:37a Bennylp
|
| 12 | * Major reorganization towards version 0.3.
|
| 13 | *
|
| 14 | */
|
| 15 | #include <pj/log.h>
|
| 16 | #include <pj/os.h>
|
| 17 | #include <pj/compat/stdfileio.h>
|
| 18 |
|
| 19 | #define CLR_FATAL (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R)
|
| 20 | #define CLR_WARNING (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R | PJ_TERM_COLOR_G)
|
| 21 | #define CLR_INFO (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | \
|
| 22 | PJ_TERM_COLOR_B)
|
| 23 | #define CLR_DEFAULT (PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | PJ_TERM_COLOR_B)
|
| 24 |
|
| 25 | static void term_set_color(int level)
|
| 26 | {
|
| 27 | #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
|
| 28 | unsigned attr = 0;
|
| 29 | switch (level) {
|
| 30 | case 0:
|
| 31 | case 1: attr = CLR_FATAL;
|
| 32 | break;
|
| 33 | case 2: attr = CLR_WARNING;
|
| 34 | break;
|
| 35 | case 3: attr = CLR_INFO;
|
| 36 | break;
|
| 37 | default:
|
| 38 | attr = CLR_DEFAULT;
|
| 39 | break;
|
| 40 | }
|
| 41 |
|
| 42 | pj_term_set_color(attr);
|
| 43 | #endif
|
| 44 | }
|
| 45 |
|
| 46 | static void term_restore_color(void)
|
| 47 | {
|
| 48 | #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
|
| 49 | pj_term_set_color(CLR_DEFAULT);
|
| 50 | #endif
|
| 51 | }
|
| 52 |
|
| 53 |
|
| 54 | PJ_DEF(void) pj_log_write(int level, const char *buffer, int len)
|
| 55 | {
|
| 56 | PJ_CHECK_STACK();
|
| 57 | PJ_UNUSED_ARG(len);
|
| 58 |
|
| 59 | /* Copy to terminal/file. */
|
| 60 | term_set_color(level);
|
| 61 | fputs(buffer, stdout);
|
| 62 | term_restore_color();
|
| 63 |
|
| 64 | fflush(stdout);
|
| 65 | }
|
| 66 |
|