? asgi-timestamp-patch3.txt Index: asterisk.c =================================================================== RCS file: /usr/cvsroot/asterisk/asterisk.c,v retrieving revision 1.141 diff -u -r1.141 asterisk.c --- asterisk.c 11 Feb 2005 21:16:34 -0000 1.141 +++ asterisk.c 24 Feb 2005 01:01:16 -0000 @@ -81,6 +81,7 @@ int option_nocolor; int option_dumpcore = 0; int option_cache_record_files = 0; +int option_timestamp = 0; int option_overrideconfig = 0; int option_reconnect = 0; int fully_booted = 0; @@ -1538,6 +1539,7 @@ printf(" -r Connect to Asterisk on this machine\n"); printf(" -R Connect to Asterisk, and attempt to reconnect if disconnected\n"); printf(" -t Record soundfiles in /var/tmp and move them where they belong after they are done.\n"); + printf(" -T Display the time in [Mmm dd hh:mm:ss] format for each line of output to the CLI.\n"); printf(" -v Increase verbosity (multiple v's = more verbose)\n"); printf(" -x Execute command (only valid with -r)\n"); printf("\n"); @@ -1610,6 +1612,9 @@ /* verbose level (-v at startup) */ if (!strcasecmp(v->name, "verbose")) { option_verbose= atoi(v->value); + /* whether or not to force timestamping. (-T at startup) */ + } else if (!strcasecmp(v->name, "timestamp")) { + option_timestamp = ast_true(v->value); /* whether or not to support #exec in config files */ } else if (!strcasecmp(v->name, "execincludes")) { option_exec_includes = ast_true(v->value); @@ -1699,7 +1704,7 @@ } */ /* Check for options */ - while((c=getopt(argc, argv, "thfdvVqprRgcinx:U:G:C:")) != -1) { + while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:")) != -1) { switch(c) { case 'd': option_debug++; @@ -1737,6 +1742,9 @@ case 't': option_cache_record_files++; break; + case 'T': + option_timestamp++; + break; case 'x': option_exec++; xarg = optarg; Index: logger.c =================================================================== RCS file: /usr/cvsroot/asterisk/logger.c,v retrieving revision 1.55 diff -u -r1.55 logger.c --- logger.c 25 Jan 2005 06:10:19 -0000 1.55 +++ logger.c 24 Feb 2005 01:01:16 -0000 @@ -597,14 +597,23 @@ if (level != __LOG_VERBOSE) { sprintf(linestr, "%d", line); - snprintf(buf, sizeof(buf), "%s %s[%ld]: %s:%s %s: ", - date, - term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)), - (long)GETTID(), - term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)), - term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)), - term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4))); - + if (!option_timestamp) + snprintf(buf, sizeof(buf), "%s %s[%ld]: %s:%s %s: ", + date, + term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)), + (long)GETTID(), + term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)), + term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)), + term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4))); + else + snprintf(buf, sizeof(buf), "[%s] %s[%ld]: %s:%s %s: ", + date, + term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)), + (long)GETTID(), + term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)), + term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)), + term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4))); + ast_console_puts(buf); va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); @@ -612,8 +621,12 @@ ast_console_puts(buf); } } else if ((chan->logmask & (1 << level)) && (chan->fileptr)) { - snprintf(buf, sizeof(buf), "%s %s[%ld]: ", date, - levels[level], (long)GETTID()); + if (!option_timestamp) + snprintf(buf, sizeof(buf), "%s %s[%ld]: ", date, + levels[level], (long)GETTID()); + else + snprintf(buf, sizeof(buf), "[%s] %s[%ld]: ", date, + levels[level], (long)GETTID()); fprintf(chan->fileptr, buf); va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); @@ -653,13 +666,37 @@ static int replacelast = 0, complete; struct msglist *m; struct verb *v; + time_t t; + struct tm tm; + char date[256]; + char datefmt[20]; + char thestring[4096]; + va_list ap; va_start(ap, fmt); ast_mutex_lock(&msglist_lock); + time(&t); + localtime_r(&t, &tm); + strftime(date, sizeof(date), dateformat, &tm); + + if (option_timestamp) { + if (date) + sprintf(datefmt, "[%s] ", date); + else + strncpy(datefmt, date, sizeof(date)); + + vsnprintf(thestring, sizeof(thestring) - 1, datefmt, ap); + pos = strlen(thestring); + + vsnprintf(thestring + pos, sizeof(thestring) - pos, fmt, ap); + + fmt = thestring; + } vsnprintf(stuff + pos, sizeof(stuff) - pos, fmt, ap); opos = pos; pos = strlen(stuff); + if (stuff[strlen(stuff)-1] == '\n') complete = 1; else @@ -699,7 +736,6 @@ } } /* else fprintf(stdout, stuff + opos); */ - ast_log(LOG_VERBOSE, "%s", stuff); if (strlen(stuff)) { if (stuff[strlen(stuff)-1] != '\n') Index: include/asterisk/options.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/options.h,v retrieving revision 1.10 diff -u -r1.10 options.h --- include/asterisk/options.h 2 Feb 2005 03:38:24 -0000 1.10 +++ include/asterisk/options.h 24 Feb 2005 01:01:18 -0000 @@ -30,6 +30,7 @@ extern int fully_booted; extern int option_exec_includes; extern int option_cache_record_files; +extern int option_timestamp; extern char defaultlanguage[]; extern time_t ast_startuptime; extern time_t ast_lastreloadtime;