Add timestamping to console (bug #3653 with minor mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5163 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 21 years ago
parent c246200ab0
commit 26c7a07735

Binary file not shown.

@ -81,6 +81,7 @@ int option_initcrypto=0;
int option_nocolor; int option_nocolor;
int option_dumpcore = 0; int option_dumpcore = 0;
int option_cache_record_files = 0; int option_cache_record_files = 0;
int option_timestamp = 0;
int option_overrideconfig = 0; int option_overrideconfig = 0;
int option_reconnect = 0; int option_reconnect = 0;
int fully_booted = 0; int fully_booted = 0;
@ -1539,6 +1540,7 @@ static int show_cli_help(void) {
printf(" -r Connect to Asterisk on this machine\n"); printf(" -r Connect to Asterisk on this machine\n");
printf(" -R Connect to Asterisk, and attempt to reconnect if disconnected\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 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(" -v Increase verbosity (multiple v's = more verbose)\n");
printf(" -x <cmd> Execute command <cmd> (only valid with -r)\n"); printf(" -x <cmd> Execute command <cmd> (only valid with -r)\n");
printf("\n"); printf("\n");
@ -1611,6 +1613,9 @@ static void ast_readconfig(void) {
/* verbose level (-v at startup) */ /* verbose level (-v at startup) */
if (!strcasecmp(v->name, "verbose")) { if (!strcasecmp(v->name, "verbose")) {
option_verbose= atoi(v->value); 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 */ /* whether or not to support #exec in config files */
} else if (!strcasecmp(v->name, "execincludes")) { } else if (!strcasecmp(v->name, "execincludes")) {
option_exec_includes = ast_true(v->value); option_exec_includes = ast_true(v->value);
@ -1700,7 +1705,7 @@ int main(int argc, char *argv[])
} }
*/ */
/* Check for options */ /* 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) { switch(c) {
case 'd': case 'd':
option_debug++; option_debug++;
@ -1738,6 +1743,9 @@ int main(int argc, char *argv[])
case 't': case 't':
option_cache_record_files++; option_cache_record_files++;
break; break;
case 'T':
option_timestamp++;
break;
case 'x': case 'x':
option_exec++; option_exec++;
xarg = optarg; xarg = optarg;

@ -21,7 +21,7 @@
<refsynopsisdiv> <refsynopsisdiv>
<cmdsynopsis> <cmdsynopsis>
<command>asterisk</command> <command>asterisk</command>
<arg><option>-hfdvVqpRgcin</option></arg> <arg><option>-tThfdvVqpRgcin</option></arg>
<arg><option>-C </option><replaceable class="parameter">file</replaceable></arg> <arg><option>-C </option><replaceable class="parameter">file</replaceable></arg>
<arg><option>-U </option><replaceable class="parameter">user</replaceable></arg> <arg><option>-U </option><replaceable class="parameter">user</replaceable></arg>
<arg><option>-G </option><replaceable class="parameter">group</replaceable></arg> <arg><option>-G </option><replaceable class="parameter">group</replaceable></arg>
@ -190,6 +190,24 @@
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-t</term>
<listitem>
<para>
When recording files, write them first into a temporary holding directory,
then move them into the final location when done.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-T</term>
<listitem>
<para>
Add timestamp to all non-command related output going to the console
when running with verbose and/or logging to the console.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-U <replaceable class="parameter">user</replaceable></term> <term>-U <replaceable class="parameter">user</replaceable></term>
<listitem> <listitem>

@ -31,6 +31,7 @@ extern int option_nocolor;
extern int fully_booted; extern int fully_booted;
extern int option_exec_includes; extern int option_exec_includes;
extern int option_cache_record_files; extern int option_cache_record_files;
extern int option_timestamp;
extern char defaultlanguage[]; extern char defaultlanguage[];
extern time_t ast_startuptime; extern time_t ast_startuptime;
extern time_t ast_lastreloadtime; extern time_t ast_lastreloadtime;

@ -601,7 +601,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
if (level != __LOG_VERBOSE) { if (level != __LOG_VERBOSE) {
sprintf(linestr, "%d", line); sprintf(linestr, "%d", line);
snprintf(buf, sizeof(buf), "%s %s[%ld]: %s:%s %s: ", snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
date, date,
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)), term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
(long)GETTID(), (long)GETTID(),
@ -616,7 +616,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
ast_console_puts(buf); ast_console_puts(buf);
} }
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) { } else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
snprintf(buf, sizeof(buf), "%s %s[%ld]: ", date, snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld]: ", date,
levels[level], (long)GETTID()); levels[level], (long)GETTID());
fprintf(chan->fileptr, buf); fprintf(chan->fileptr, buf);
va_start(ap, fmt); va_start(ap, fmt);
@ -657,13 +657,30 @@ extern void ast_verbose(const char *fmt, ...)
static int replacelast = 0, complete; static int replacelast = 0, complete;
struct msglist *m; struct msglist *m;
struct verb *v; struct verb *v;
time_t t;
struct tm tm;
char date[40];
char *datefmt;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
ast_mutex_lock(&msglist_lock); ast_mutex_lock(&msglist_lock);
time(&t);
localtime_r(&t, &tm);
strftime(date, sizeof(date), dateformat, &tm);
if (option_timestamp) {
datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
if (datefmt) {
sprintf(datefmt, "[%s] %s", date, fmt);
fmt = datefmt;
}
}
vsnprintf(stuff + pos, sizeof(stuff) - pos, fmt, ap); vsnprintf(stuff + pos, sizeof(stuff) - pos, fmt, ap);
opos = pos; opos = pos;
pos = strlen(stuff); pos = strlen(stuff);
if (stuff[strlen(stuff)-1] == '\n') if (stuff[strlen(stuff)-1] == '\n')
complete = 1; complete = 1;
else else
@ -703,7 +720,6 @@ extern void ast_verbose(const char *fmt, ...)
} }
} /* else } /* else
fprintf(stdout, stuff + opos); */ fprintf(stdout, stuff + opos); */
ast_log(LOG_VERBOSE, "%s", stuff); ast_log(LOG_VERBOSE, "%s", stuff);
if (strlen(stuff)) { if (strlen(stuff)) {
if (stuff[strlen(stuff)-1] != '\n') if (stuff[strlen(stuff)-1] != '\n')

Loading…
Cancel
Save