This will be more useful later when we introduces "worker" subprocesses.
I don't have any current plans to introduce threading, but I can't
think of a disadvantage to wording this in a general manner.
Signed-off-by: Ben Pfaff <blp@nicira.com>
post-v1.8.0
------------------------
+ - New %t and %T log escapes to identify the subprogram within a
+ cooperating group of processes or threads that emitted a log message.
+ The default log patterns now include this information.
v1.8.0 - xx xxx xxxx
monitor_daemon(pid_t daemon_pid)
{
/* XXX Should log daemon's stderr output at startup time. */
- const char *saved_program_name;
time_t last_restart;
char *status_msg;
int crashes;
- saved_program_name = program_name;
- program_name = xasprintf("monitor(%s)", program_name);
+ subprogram_name = "monitor";
status_msg = xstrdup("healthy");
last_restart = TIME_MIN;
crashes = 0;
int status;
proctitle_set("%s: monitoring pid %lu (%s)",
- saved_program_name, (unsigned long int) daemon_pid,
+ program_name, (unsigned long int) daemon_pid,
status_msg);
do {
/* Running in new daemon process. */
proctitle_restore();
- free((char *) program_name);
- program_name = saved_program_name;
+ subprogram_name = "";
}
/* Close standard file descriptors (except any that the client has requested we
COVERAGE_DEFINE(util_xalloc);
+/* argv[0] without directory names. */
const char *program_name;
+
+/* Ordinarily "" but set to "monitor" for a monitor process or "worker" for a
+ * worker process. */
+const char *subprogram_name = "";
+
+/* --version option output. */
static char *program_version;
void
{
int save_errno = errno;
- fprintf(stderr, "%s: ", program_name);
+ if (subprogram_name[0]) {
+ fprintf(stderr, "%s(%s): ", program_name, subprogram_name);
+ } else {
+ fprintf(stderr, "%s: ", program_name);
+ }
+
vfprintf(stderr, format, args);
if (err_no != 0) {
fprintf(stderr, " (%s)", ovs_retval_to_string(err_no));
#endif
extern const char *program_name;
+extern const char *subprogram_name;
/* Returns the number of elements in ARRAY. */
#define ARRAY_SIZE(ARRAY) (sizeof ARRAY / sizeof *ARRAY)
case 'r':
ds_put_format(s, "%lld", time_msec() - time_boot_msec());
break;
+ case 't':
+ ds_put_cstr(s, subprogram_name[0] ? subprogram_name : "main");
+ break;
+ case 'T':
+ if (subprogram_name[0]) {
+ ds_put_format(s, "(%s)", subprogram_name);
+ }
+ break;
default:
ds_put_char(s, p[-1]);
break;
enum vlog_level vlog_get_level_val(const char *name);
/* Facilities that we can log to. */
-#define VLOG_FACILITIES \
- VLOG_FACILITY(SYSLOG, "%05N|%c|%p|%m") \
- VLOG_FACILITY(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c|%p|%m") \
- VLOG_FACILITY(FILE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c|%p|%m")
+#define VLOG_FACILITIES \
+ VLOG_FACILITY(SYSLOG, "%05N|%c%T|%p|%m") \
+ VLOG_FACILITY(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m") \
+ VLOG_FACILITY(FILE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m")
enum vlog_facility {
#define VLOG_FACILITY(NAME, PATTERN) VLF_##NAME,
VLOG_FACILITIES
The number of milliseconds elapsed from the start of the application
to the time the message was logged.
.
+.IP \fB%t\fR
+The subprogram name, that is, an identifying name for the process or
+thread that emitted the log message, such as \fBmonitor\fR for the
+process used for \fB\-\-monitor\fR or \fBmain\fR for the primary
+process or thread in a program.
+.
+.IP \fB%T\fR
+The subprogram name enclosed in parentheses, e.g. \fB(monitor)\fR, or
+the empty string for the primary process or thread in a program.
+.
.IP \fB%%\fR
A literal \fB%\fR.
.RE