diff --git a/config.c b/config.c index 7bb949d..e6fe676 100644 --- a/config.c +++ b/config.c @@ -199,6 +199,7 @@ struct config_item config_tab[] = { PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX), PORT_ITEM_INT("logSyncInterval", 0, INT8_MIN, INT8_MAX), GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX), + GLOB_ITEM_STR("message_tag", NULL), GLOB_ITEM_STR("manufacturerIdentity", "00:00:00"), GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX), PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1), diff --git a/phc2sys.8 b/phc2sys.8 index 22d02c2..2559c74 100644 --- a/phc2sys.8 +++ b/phc2sys.8 @@ -206,6 +206,10 @@ The default is /var/run/ptp4l. Set the maximum syslog level of messages which should be printed or sent to the system logger. The default is 6 (LOG_INFO). .TP +.BI \-t " message-tag" +Specify the tag which is added to all messages printed to the standard output +or system log. The default is an empty string. +.TP .B \-m Print messages to the standard output. .TP diff --git a/phc2sys.c b/phc2sys.c index 35cf6fa..aa4186b 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -1209,6 +1209,7 @@ static void usage(char *progname) " -x apply leap seconds by servo instead of kernel\n" " -z [path] server address for UDS (/var/run/ptp4l)\n" " -l [num] set the logging level to 'num' (6)\n" + " -t [tag] add tag to log messages\n" " -m print messages to stdout\n" " -q do not print messages to the syslog\n" " -v prints the software version and exits\n" @@ -1219,7 +1220,7 @@ static void usage(char *progname) int main(int argc, char *argv[]) { - char *progname; + char *progname, *message_tag = NULL; char *src_name = NULL, *dst_name = NULL; struct clock *src, *dst; struct config *cfg; @@ -1251,7 +1252,7 @@ int main(int argc, char *argv[]) progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; while (EOF != (c = getopt(argc, argv, - "arc:d:s:E:P:I:S:F:R:N:O:L:M:i:u:wn:xz:l:mqvh"))) { + "arc:d:s:E:P:I:S:F:R:N:O:L:M:i:u:wn:xz:l:t:mqvh"))) { switch (c) { case 'a': autocfg = 1; @@ -1363,6 +1364,9 @@ int main(int argc, char *argv[]) PRINT_LEVEL_MIN, PRINT_LEVEL_MAX)) goto end; break; + case 't': + message_tag = optarg; + break; case 'm': verbose = 1; break; @@ -1405,6 +1409,7 @@ int main(int argc, char *argv[]) } print_set_progname(progname); + print_set_tag(message_tag); print_set_verbose(verbose); print_set_syslog(use_syslog); print_set_level(print_level); diff --git a/print.c b/print.c index a82d0e7..6c48e1e 100644 --- a/print.c +++ b/print.c @@ -28,12 +28,18 @@ static int verbose = 0; static int print_level = LOG_INFO; static int use_syslog = 1; static const char *progname; +static const char *message_tag; void print_set_progname(const char *name) { progname = name; } +void print_set_tag(const char *tag) +{ + message_tag = tag; +} + void print_set_syslog(int value) { use_syslog = value ? 1 : 0; @@ -67,13 +73,17 @@ void print(int level, char const *format, ...) if (verbose) { f = level >= LOG_NOTICE ? stdout : stderr; - fprintf(f, "%s[%ld.%03ld]: %s\n", + fprintf(f, "%s[%ld.%03ld]: %s%s%s\n", progname ? progname : "", - ts.tv_sec, ts.tv_nsec / 1000000, buf); + ts.tv_sec, ts.tv_nsec / 1000000, + message_tag ? message_tag : "", message_tag ? " " : "", + buf); fflush(f); } if (use_syslog) { - syslog(level, "[%ld.%03ld] %s", - ts.tv_sec, ts.tv_nsec / 1000000, buf); + syslog(level, "[%ld.%03ld] %s%s%s", + ts.tv_sec, ts.tv_nsec / 1000000, + message_tag ? message_tag : "", message_tag ? " " : "", + buf); } } diff --git a/print.h b/print.h index e8f2c8e..1723d8a 100644 --- a/print.h +++ b/print.h @@ -33,6 +33,7 @@ __attribute__ ((format (printf, 2, 3))) void print(int level, char const *format, ...); void print_set_progname(const char *name); +void print_set_tag(const char *tag); void print_set_syslog(int value); void print_set_level(int level); void print_set_verbose(int value); diff --git a/ptp4l.8 b/ptp4l.8 index 53d5f28..a724151 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -485,6 +485,12 @@ is 0. The maximum logging level of messages which should be printed. The default is 6 (LOG_INFO). .TP +.B message_tag +The tag which is added to all messages printed to the standard output or system +log. +The default is an empty string (which cannot be set in the configuration file +as the option requires an argument). +.TP .B verbose Print messages to the standard output if enabled. The default is 0 (disabled). diff --git a/ptp4l.c b/ptp4l.c index e90fcb2..f01ff6f 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -183,6 +183,7 @@ int main(int argc, char *argv[]) } print_set_progname(progname); + print_set_tag(config_get_string(cfg, NULL, "message_tag")); print_set_verbose(config_get_int(cfg, NULL, "verbose")); print_set_syslog(config_get_int(cfg, NULL, "use_syslog")); print_set_level(config_get_int(cfg, NULL, "logging_level"));