Index: /pjproject/trunk/pjlib/include/pj/log.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/log.h	(revision 2158)
+++ /pjproject/trunk/pjlib/include/pj/log.h	(revision 2159)
@@ -69,13 +69,15 @@
 enum pj_log_decoration
 {
-    PJ_LOG_HAS_DAY_NAME   =   1, /**< Include day name [default: no].	     */
-    PJ_LOG_HAS_YEAR       =   2, /**< Include year digit [default: no]	     */
-    PJ_LOG_HAS_MONTH	  =   4, /**< Include month [default: no]	     */
-    PJ_LOG_HAS_DAY_OF_MON =   8, /**< Include day of month [default: no]     */
-    PJ_LOG_HAS_TIME	  =  16, /**< Include time [default: yes].	     */
-    PJ_LOG_HAS_MICRO_SEC  =  32, /**< Include microseconds [yes]             */
-    PJ_LOG_HAS_SENDER	  =  64, /**< Include sender in the log [yes].	     */
-    PJ_LOG_HAS_NEWLINE	  = 128, /**< Terminate each call with newline [yes].*/
-    PJ_LOG_HAS_CR	  = 256  /**< Include carriage return [no].	     */
+    PJ_LOG_HAS_DAY_NAME   =    1, /**< Include day name [default: no] 	      */
+    PJ_LOG_HAS_YEAR       =    2, /**< Include year digit [no]		      */
+    PJ_LOG_HAS_MONTH	  =    4, /**< Include month [no]		      */
+    PJ_LOG_HAS_DAY_OF_MON =    8, /**< Include day of month [no]	      */
+    PJ_LOG_HAS_TIME	  =   16, /**< Include time [yes]		      */
+    PJ_LOG_HAS_MICRO_SEC  =   32, /**< Include microseconds [yes]             */
+    PJ_LOG_HAS_SENDER	  =   64, /**< Include sender in the log [yes] 	      */
+    PJ_LOG_HAS_NEWLINE	  =  128, /**< Terminate each call with newline [yes] */
+    PJ_LOG_HAS_CR	  =  256, /**< Include carriage return [no] 	      */
+    PJ_LOG_HAS_SPACE	  =  512, /**< Include two spaces before log [yes]    */
+    PJ_LOG_HAS_COLOR	  = 1024  /**< Colorize logs [yes on win32]	      */
 };
 
@@ -200,4 +202,21 @@
 
 
+/**
+ * Set color of log messages.
+ *
+ * @param level	    Log level which color will be changed.
+ * @param color	    Desired color.
+ */
+PJ_DECL(void) pj_log_set_color(int level, pj_color_t color);
+
+/**
+ * Get color of log messages.
+ *
+ * @param level	    Log level which color will be returned.
+ * @return	    Log color.
+ */
+PJ_DECL(pj_color_t) pj_log_get_color(int level);
+
+
 #else	/* #if PJ_LOG_MAX_LEVEL >= 1 */
 
@@ -237,4 +256,12 @@
 
 /**
+ * Set color of log messages.
+ *
+ * @param level	    Log level which color will be changed.
+ * @param color	    Desired color.
+ */
+#  define pj_log_set_color(level, color)
+
+/**
  * Get current maximum log verbositylevel.
  *
@@ -249,4 +276,12 @@
  */
 #  define pj_log_get_decor()	0
+
+/**
+ * Get color of log messages.
+ *
+ * @param level	    Log level which color will be returned.
+ * @return	    Log color.
+ */
+#  define pj_log_get_color(level) 0
 
 
Index: /pjproject/trunk/pjlib/src/pj/log.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/log.c	(revision 2158)
+++ /pjproject/trunk/pjlib/src/pj/log.c	(revision 2159)
@@ -32,5 +32,33 @@
 static pj_log_func *log_writer = &pj_log_write;
 static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC |
-			    PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE;
+			    PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE |
+			    PJ_LOG_HAS_SPACE 
+#if defined(PJ_WIN32) && PJ_WIN32!=0
+			    | PJ_LOG_HAS_COLOR
+#endif
+			    ;
+
+static pj_color_t PJ_LOG_COLOR_0 = PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R;
+static pj_color_t PJ_LOG_COLOR_1 = PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R;
+static pj_color_t PJ_LOG_COLOR_2 = PJ_TERM_COLOR_BRIGHT | 
+				   PJ_TERM_COLOR_R | 
+				   PJ_TERM_COLOR_G;
+static pj_color_t PJ_LOG_COLOR_3 = PJ_TERM_COLOR_BRIGHT | 
+				   PJ_TERM_COLOR_R | 
+				   PJ_TERM_COLOR_G | 
+				   PJ_TERM_COLOR_B;
+static pj_color_t PJ_LOG_COLOR_4 = PJ_TERM_COLOR_R | 
+				   PJ_TERM_COLOR_G | 
+				   PJ_TERM_COLOR_B;
+static pj_color_t PJ_LOG_COLOR_5 = PJ_TERM_COLOR_R | 
+				   PJ_TERM_COLOR_G | 
+				   PJ_TERM_COLOR_B;
+static pj_color_t PJ_LOG_COLOR_6 = PJ_TERM_COLOR_R | 
+				   PJ_TERM_COLOR_G | 
+				   PJ_TERM_COLOR_B;
+/* Default terminal color */
+static pj_color_t PJ_LOG_COLOR_77 = PJ_TERM_COLOR_R | 
+				    PJ_TERM_COLOR_G | 
+				    PJ_TERM_COLOR_B;
 
 #if PJ_LOG_USE_STACK_BUFFER==0
@@ -46,4 +74,54 @@
 {
     return log_decor;
+}
+
+PJ_DEF(void) pj_log_set_color(int level, pj_color_t color)
+{
+    switch (level) 
+    {
+	case 0: PJ_LOG_COLOR_0 = color; 
+	    break;
+	case 1: PJ_LOG_COLOR_1 = color; 
+	    break;
+	case 2: PJ_LOG_COLOR_2 = color; 
+	    break;
+	case 3: PJ_LOG_COLOR_3 = color; 
+	    break;
+	case 4: PJ_LOG_COLOR_4 = color; 
+	    break;
+	case 5: PJ_LOG_COLOR_5 = color; 
+	    break;
+	case 6: PJ_LOG_COLOR_6 = color; 
+	    break;
+	/* Default terminal color */
+	case 77: PJ_LOG_COLOR_77 = color; 
+	    break;
+	default:
+	    /* Do nothing */
+	    break;
+    }
+}
+
+PJ_DEF(pj_color_t) pj_log_get_color(int level)
+{
+    switch (level) {
+	case 0:
+	    return PJ_LOG_COLOR_0;
+	case 1:
+	    return PJ_LOG_COLOR_1;
+	case 2:
+	    return PJ_LOG_COLOR_2;
+	case 3:
+	    return PJ_LOG_COLOR_3;
+	case 4:
+	    return PJ_LOG_COLOR_4;
+	case 5:
+	    return PJ_LOG_COLOR_5;
+	case 6:
+	    return PJ_LOG_COLOR_6;
+	default:
+	    /* Return default terminal color */
+	    return PJ_LOG_COLOR_77;
+    }
 }
 
@@ -106,5 +184,5 @@
     }
     if (log_decor & PJ_LOG_HAS_DAY_OF_MON) {
-	*pre++ = ' ';
+	*pre++ = '-';
 	pre += pj_utoa_pad(ptime.day, pre, 2, '0');
     }
@@ -140,4 +218,8 @@
 	*pre++ = ' ';
 
+    if (log_decor & PJ_LOG_HAS_SPACE) {
+	*pre++ = ' ';
+    }
+
     len = pre - log_buffer;
 
Index: /pjproject/trunk/pjlib/src/pj/log_writer_stdout.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/log_writer_stdout.c	(revision 2158)
+++ /pjproject/trunk/pjlib/src/pj/log_writer_stdout.c	(revision 2159)
@@ -21,28 +21,9 @@
 #include <pj/compat/stdfileio.h>
 
-#define CLR_FATAL    (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R)
-#define CLR_WARNING  (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R | PJ_TERM_COLOR_G)
-#define CLR_INFO     (PJ_TERM_COLOR_BRIGHT | PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | \
-		      PJ_TERM_COLOR_B)
-#define CLR_DEFAULT  (PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | PJ_TERM_COLOR_B)
 
 static void term_set_color(int level)
 {
 #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
-    unsigned attr = 0;
-    switch (level) {
-    case 0:
-    case 1: attr = CLR_FATAL; 
-	break;
-    case 2: attr = CLR_WARNING; 
-	break;
-    case 3: attr = CLR_INFO; 
-	break;
-    default:
-	attr = CLR_DEFAULT;
-	break;
-    }
-
-    pj_term_set_color(attr);
+    pj_term_set_color(pj_log_get_color(level));
 #endif
 }
@@ -51,5 +32,6 @@
 {
 #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
-    pj_term_set_color(CLR_DEFAULT);
+    /* Set terminal to its default color */
+    pj_term_set_color(pj_log_get_color(77));
 #endif
 }
@@ -62,7 +44,11 @@
 
     /* Copy to terminal/file. */
-    term_set_color(level);
-    printf("%s", buffer);
-    term_restore_color();
+    if (pj_log_get_decor() & PJ_LOG_HAS_COLOR) {
+	term_set_color(level);
+	printf("%s", buffer);
+	term_restore_color();
+    } else {
+	printf("%s", buffer);
+    }
 }
 
Index: /pjproject/trunk/pjlib/src/pj/os_core_unix.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/os_core_unix.c	(revision 2158)
+++ /pjproject/trunk/pjlib/src/pj/os_core_unix.c	(revision 2159)
@@ -1690,6 +1690,55 @@
 PJ_DEF(pj_status_t) pj_term_set_color(pj_color_t color)
 {
-    PJ_UNUSED_ARG(color);
-    return PJ_EINVALIDOP;
+    /* put bright prefix to ansi_color */
+    char ansi_color[12] = "\033[01;3";
+
+    if (color & PJ_TERM_COLOR_BRIGHT) {
+	color ^= PJ_TERM_COLOR_BRIGHT;
+    } else {
+	strcpy(ansi_color, "\033[00;3");
+    }
+
+    switch (color) {
+    case 0:
+	/* black color */
+	strcat(ansi_color, "0m");
+	break;
+    case PJ_TERM_COLOR_R:
+	/* red color */
+	strcat(ansi_color, "1m");
+	break;
+    case PJ_TERM_COLOR_G:
+	/* green color */
+	strcat(ansi_color, "2m");
+	break;
+    case PJ_TERM_COLOR_B:
+	/* blue color */
+	strcat(ansi_color, "4m");
+	break;
+    case PJ_TERM_COLOR_R | PJ_TERM_COLOR_G:
+	/* yellow color */
+	strcat(ansi_color, "3m");
+	break;
+    case PJ_TERM_COLOR_R | PJ_TERM_COLOR_B:
+	/* magenta color */
+	strcat(ansi_color, "5m");
+	break;
+    case PJ_TERM_COLOR_G | PJ_TERM_COLOR_B:
+	/* cyan color */
+	strcat(ansi_color, "6m");
+	break;
+    case PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | PJ_TERM_COLOR_B:
+	/* white color */
+	strcat(ansi_color, "7m");
+	break;
+    default:
+	/* default console color */
+	strcpy(ansi_color, "\033[00m");
+	break;
+    }
+
+    fputs(ansi_color, stdout);
+
+    return PJ_SUCCESS;
 }
 
Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2158)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2159)
@@ -159,4 +159,7 @@
     puts  ("  --log-level=N       Set log max level to N (0(none) to 6(trace)) (default=5)");
     puts  ("  --app-log-level=N   Set log max level for stdout display (default=4)");
+    puts  ("  --color             Use colorful logging (default yes on Win32)");
+    puts  ("  --no-color          Disable colorful logging");
+
     puts  ("");
     puts  ("SIP Account options:");
@@ -443,4 +446,5 @@
     int option_index;
     enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, 
+	   OPT_COLOR, OPT_NO_COLOR,
 	   OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_SND_AUTO_CLOSE,
 	   OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, 
@@ -477,4 +481,6 @@
 	{ "log-level",	1, 0, OPT_LOG_LEVEL},
 	{ "app-log-level",1,0,OPT_APP_LOG_LEVEL},
+	{ "color",	0, 0, OPT_COLOR},
+	{ "no-color",	0, 0, OPT_NO_COLOR},
 	{ "help",	0, 0, OPT_HELP},
 	{ "version",	0, 0, OPT_VERSION},
@@ -638,4 +644,12 @@
 	    break;
 
+	case OPT_COLOR:
+	    cfg->log_cfg.decor |= PJ_LOG_HAS_COLOR;
+	    break;
+
+	case OPT_NO_COLOR:
+	    cfg->log_cfg.decor &= ~PJ_LOG_HAS_COLOR;
+	    break;
+
 	case OPT_HELP:
 	    usage();
@@ -3757,5 +3771,5 @@
 		len = write_settings(&app_config, settings, sizeof(settings));
 		if (len < 1)
-		    PJ_LOG(3,(THIS_FILE, "Error: not enough buffer"));
+		    PJ_LOG(1,(THIS_FILE, "Error: not enough buffer"));
 		else
 		    PJ_LOG(3,(THIS_FILE, 
@@ -3784,5 +3798,5 @@
 		len = write_settings(&app_config, settings, sizeof(settings));
 		if (len < 1)
-		    PJ_LOG(3,(THIS_FILE, "Error: not enough buffer"));
+		    PJ_LOG(1,(THIS_FILE, "Error: not enough buffer"));
 		else {
 		    pj_oshandle_t fd;
@@ -4082,5 +4096,5 @@
 
     if (transport_id == -1) {
-	PJ_LOG(3,(THIS_FILE, "Error: no transport is configured"));
+	PJ_LOG(1,(THIS_FILE, "Error: no transport is configured"));
 	status = -1;
 	goto on_error;
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 2158)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 2159)
@@ -41,5 +41,5 @@
 
     pj_strerror(status, errmsg, sizeof(errmsg));
-    PJ_LOG(3,(sender, "%s: %s [status=%d]", title, errmsg, status));
+    PJ_LOG(1,(sender, "%s: %s [status=%d]", title, errmsg, status));
 }
 
@@ -70,5 +70,9 @@
     cfg->console_level = 4;
     cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME | 
-		 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE;
+		 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE |
+		 PJ_LOG_HAS_SPACE;
+#if defined(PJ_WIN32) && PJ_WIN32 != 0
+    cfg->decor |= PJ_LOG_HAS_COLOR;
+#endif
 }
 
