Add options to tag ptp4l and phc2sys log messages.
When running multiple instances of ptp4l or phc2sys, it's difficult to tell which log message belongs to which instance. Add new options to ptp4l and phc2sys which can specify a tag for all messages printed to the standard output or system log, so messages from different instances can have different tags. Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>master
parent
33e62f9925
commit
0f6c6972c7
1
config.c
1
config.c
|
@ -199,6 +199,7 @@ struct config_item config_tab[] = {
|
||||||
PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
|
PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
|
||||||
PORT_ITEM_INT("logSyncInterval", 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_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_STR("manufacturerIdentity", "00:00:00"),
|
||||||
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
|
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
|
||||||
PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1),
|
PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1),
|
||||||
|
|
|
@ -206,6 +206,10 @@ The default is /var/run/ptp4l.
|
||||||
Set the maximum syslog level of messages which should be printed or sent to
|
Set the maximum syslog level of messages which should be printed or sent to
|
||||||
the system logger. The default is 6 (LOG_INFO).
|
the system logger. The default is 6 (LOG_INFO).
|
||||||
.TP
|
.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
|
.B \-m
|
||||||
Print messages to the standard output.
|
Print messages to the standard output.
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -1209,6 +1209,7 @@ static void usage(char *progname)
|
||||||
" -x apply leap seconds by servo instead of kernel\n"
|
" -x apply leap seconds by servo instead of kernel\n"
|
||||||
" -z [path] server address for UDS (/var/run/ptp4l)\n"
|
" -z [path] server address for UDS (/var/run/ptp4l)\n"
|
||||||
" -l [num] set the logging level to 'num' (6)\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"
|
" -m print messages to stdout\n"
|
||||||
" -q do not print messages to the syslog\n"
|
" -q do not print messages to the syslog\n"
|
||||||
" -v prints the software version and exits\n"
|
" -v prints the software version and exits\n"
|
||||||
|
@ -1219,7 +1220,7 @@ static void usage(char *progname)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *progname;
|
char *progname, *message_tag = NULL;
|
||||||
char *src_name = NULL, *dst_name = NULL;
|
char *src_name = NULL, *dst_name = NULL;
|
||||||
struct clock *src, *dst;
|
struct clock *src, *dst;
|
||||||
struct config *cfg;
|
struct config *cfg;
|
||||||
|
@ -1251,7 +1252,7 @@ int main(int argc, char *argv[])
|
||||||
progname = strrchr(argv[0], '/');
|
progname = strrchr(argv[0], '/');
|
||||||
progname = progname ? 1+progname : argv[0];
|
progname = progname ? 1+progname : argv[0];
|
||||||
while (EOF != (c = getopt(argc, argv,
|
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) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
autocfg = 1;
|
autocfg = 1;
|
||||||
|
@ -1363,6 +1364,9 @@ int main(int argc, char *argv[])
|
||||||
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX))
|
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX))
|
||||||
goto end;
|
goto end;
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
message_tag = optarg;
|
||||||
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -1405,6 +1409,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
print_set_progname(progname);
|
print_set_progname(progname);
|
||||||
|
print_set_tag(message_tag);
|
||||||
print_set_verbose(verbose);
|
print_set_verbose(verbose);
|
||||||
print_set_syslog(use_syslog);
|
print_set_syslog(use_syslog);
|
||||||
print_set_level(print_level);
|
print_set_level(print_level);
|
||||||
|
|
18
print.c
18
print.c
|
@ -28,12 +28,18 @@ static int verbose = 0;
|
||||||
static int print_level = LOG_INFO;
|
static int print_level = LOG_INFO;
|
||||||
static int use_syslog = 1;
|
static int use_syslog = 1;
|
||||||
static const char *progname;
|
static const char *progname;
|
||||||
|
static const char *message_tag;
|
||||||
|
|
||||||
void print_set_progname(const char *name)
|
void print_set_progname(const char *name)
|
||||||
{
|
{
|
||||||
progname = name;
|
progname = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_set_tag(const char *tag)
|
||||||
|
{
|
||||||
|
message_tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
void print_set_syslog(int value)
|
void print_set_syslog(int value)
|
||||||
{
|
{
|
||||||
use_syslog = value ? 1 : 0;
|
use_syslog = value ? 1 : 0;
|
||||||
|
@ -67,13 +73,17 @@ void print(int level, char const *format, ...)
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
f = level >= LOG_NOTICE ? stdout : stderr;
|
f = level >= LOG_NOTICE ? stdout : stderr;
|
||||||
fprintf(f, "%s[%ld.%03ld]: %s\n",
|
fprintf(f, "%s[%ld.%03ld]: %s%s%s\n",
|
||||||
progname ? progname : "",
|
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);
|
fflush(f);
|
||||||
}
|
}
|
||||||
if (use_syslog) {
|
if (use_syslog) {
|
||||||
syslog(level, "[%ld.%03ld] %s",
|
syslog(level, "[%ld.%03ld] %s%s%s",
|
||||||
ts.tv_sec, ts.tv_nsec / 1000000, buf);
|
ts.tv_sec, ts.tv_nsec / 1000000,
|
||||||
|
message_tag ? message_tag : "", message_tag ? " " : "",
|
||||||
|
buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
print.h
1
print.h
|
@ -33,6 +33,7 @@ __attribute__ ((format (printf, 2, 3)))
|
||||||
void print(int level, char const *format, ...);
|
void print(int level, char const *format, ...);
|
||||||
|
|
||||||
void print_set_progname(const char *name);
|
void print_set_progname(const char *name);
|
||||||
|
void print_set_tag(const char *tag);
|
||||||
void print_set_syslog(int value);
|
void print_set_syslog(int value);
|
||||||
void print_set_level(int level);
|
void print_set_level(int level);
|
||||||
void print_set_verbose(int value);
|
void print_set_verbose(int value);
|
||||||
|
|
6
ptp4l.8
6
ptp4l.8
|
@ -485,6 +485,12 @@ is 0.
|
||||||
The maximum logging level of messages which should be printed.
|
The maximum logging level of messages which should be printed.
|
||||||
The default is 6 (LOG_INFO).
|
The default is 6 (LOG_INFO).
|
||||||
.TP
|
.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
|
.B verbose
|
||||||
Print messages to the standard output if enabled.
|
Print messages to the standard output if enabled.
|
||||||
The default is 0 (disabled).
|
The default is 0 (disabled).
|
||||||
|
|
1
ptp4l.c
1
ptp4l.c
|
@ -183,6 +183,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
print_set_progname(progname);
|
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_verbose(config_get_int(cfg, NULL, "verbose"));
|
||||||
print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
|
print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
|
||||||
print_set_level(config_get_int(cfg, NULL, "logging_level"));
|
print_set_level(config_get_int(cfg, NULL, "logging_level"));
|
||||||
|
|
Loading…
Reference in New Issue