Feature request: Switch to disable timestamps in stdout
A message that is not in the archive (sent off-list or not yet received): [email protected]...
A message that is not in the archive (sent off-list or not yet received): [email protected]...
Quoted 11 lines · James Yonan
Quoted 10 lines · Charles Duffy
I'm using OpenVPN under a process supervision framework that (optionally) adds its own timestamps in the form YYYY-MM-DD_HH:MM:SS.xxxxx to the beginning of each line's output when sending said output to a logfile. I'm using this for all my other services, and would like to do it for OpenVPN too (so I can use cat and sort to see combined logs from any arbitrary set of services). However, when doing so, I get both OpenVPN's own timestamps and the framework's timestamps next to each other -- somewhat less than ideal. I don't see anything in the OpenVPN man page describing a way to disable these timestamps. Such an option would be useful, though.
Quoted 6 lines
Quoted 2 lines
James, would you object to adding such an option? If you like, I'd be glad to try my hand at creating a patch for it, with semantics of your choice.
I don't have any problem with this -- in fact the timestamp is already removed for output to the system logger, so you can see how this is currently done.
A proposed patch is attached.
error.c +11 -1
@@ -72,6 +72,9 @@/* Should messages be written to the syslog? */ static bool use_syslog;/* GLOBAL */ +/* Should timestamps be included on messages to stdout/stderr? */ +static bool suppress_timestamps;/* GLOBAL */ +/* The program name passed to syslog */ static char *pgmname_syslog;/* GLOBAL */
@@ -91,9 +94,16 @@ }void +set_suppress_timestamps (bool suppressed) +{ + suppress_timestamps = suppressed; +} + +void error_reset () { use_syslog = std_redir = false; + suppress_timestamps = false; x_debug_level =1 ; mute_cutoff =0 ; mute_count =0 ;
@@ -252,7 +262,7 @@FILE *fp =msg_fp ();const bool show_usec =check_debug_level (DEBUG_LEVEL_USEC_TIME -1 ); -if (flags &M_NOPREFIX ) +if (flags &M_NOPREFIX || suppress_timestamps) { fprintf (fp, "%s%s%s\n", prefix,
error.h +1 -0
@@ -152,6 +152,7 @@void error_reset (void );void set_debug_level (int level);void set_mute_cutoff (int cutoff); +void set_suppress_timestamps (bool suppressed);/* * File to print messages to before syslog is opened.
openvpn.8 +7 -0
@@ -161,6 +161,7 @@ [\ \fB\-\-local\fR\ \fIhost\fR\ ] [\ \fB\-\-log\-append\fR\ \fIfile\fR\ ] [\ \fB\-\-log\fR\ \fIfile\fR\ ] +[\ \fB\-\-suppress-timestamps\fR\ ] [\ \fB\-\-lport\fR\ \fIport\fR\ ] [\ \fB\-\-max\-clients\fR\ \fIn\fR\ ] [\ \fB\-\-mktun\fR\ ]
@@ -1746,6 +1747,12 @@ than truncating the log file. .\"********************************************************* .TP +.B --suppress-timestamps +Avoid writing timestamps to log messages, even when they +otherwise would be prepended. In particular, this applies to +log messages sent to stdout. +.\"********************************************************* +.TP .B --writepid file Write OpenVPN's main process ID to .B file.
options.c +9 -0
@@ -210,6 +210,7 @@" See --daemon above for a description of the 'name' parm.\n" "--log file : Output log to file which is created/truncated on open.\n" "--log-append file : Append log to file, or create file if nonexistent.\n" +"--suppress-timestamps : Don't log timestamps to stdout/stderr.\n" "--writepid file : Write main process ID to file.\n" "--nice n : Change process priority (>0 = lower, <0 = higher).\n" #ifdef USE_PTHREAD
@@ -854,6 +855,7 @@SHOW_BOOL (daemon);SHOW_INT (inetd);SHOW_BOOL (log); +SHOW_BOOL (suppress_timestamps);SHOW_INT (nice);SHOW_INT (verbosity);SHOW_INT (mute);
@@ -2293,6 +2295,13 @@ options->log = true;redirect_stdout_stderr (p[1 ], false); } +else if (streq (p[0 ],"suppress-timestamps" )) + { + ++i; +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->suppress_timestamps = true; +set_suppress_timestamps (true); + }else if (streq (p[0 ],"log-append" ) && p[1 ]) { ++i;
options.h +1 -0
@@ -183,6 +183,7 @@int inetd;bool log; +bool suppress_timestamps;int nice;int verbosity;int mute;