Skip to content

Commit e47d5db

Browse files
liuhangbinjpirko
authored andcommitted
teamd: add an option to force log output to stdout, stderr or syslog
By default, libdaemon prints the logs to stderr, and switches to syslog if the precess daemonizes. When some users, e.g. NetworkManager, run teamd foreground, the logs printed in syslog will as coming from NetworkManager, with mixed NetworkManager's own debug logs, which makes people feel a mess and hard to debug. Add option -l to support force teamd log output to stdout, stderr or syslog. Also add a global env TEAM_LOG_OUTPUT, which could be used for old version compatibility. Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
1 parent b6f63db commit e47d5db

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

man/teamd.8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Use the specified PID file.
6969
.B "\-g, \-\-debug"
7070
Turns on debugging messages. Repeating the option increases verbosity.
7171
.TP
72+
.B "\-l, \-\-log-output"
73+
Force teamd log output to stdout, stderr or syslog.
74+
.TP
7275
.B "\-r, \-\-force-recreate"
7376
Force team device recreation in case it already exists.
7477
.TP

teamd/teamd.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static void print_help(const struct teamd_context *ctx) {
107107
" file will be ignored)\n"
108108
" -p --pid-file=FILE Use the specified PID file\n"
109109
" -g --debug Increase verbosity\n"
110+
" -l --log-output Force teamd log output to stdout, stderr or syslog\n"
110111
" -r --force-recreate Force team device recreation in case it\n"
111112
" already exists\n"
112113
" -o --take-over Take over the device if it already exists\n"
@@ -140,6 +141,7 @@ static int parse_command_line(struct teamd_context *ctx,
140141
{ "config", required_argument, NULL, 'c' },
141142
{ "pid-file", required_argument, NULL, 'p' },
142143
{ "debug", no_argument, NULL, 'g' },
144+
{ "log-output", required_argument, NULL, 'l' },
143145
{ "force-recreate", no_argument, NULL, 'r' },
144146
{ "take-over", no_argument, NULL, 'o' },
145147
{ "no-quit-destroy", no_argument, NULL, 'N' },
@@ -152,7 +154,7 @@ static int parse_command_line(struct teamd_context *ctx,
152154
{ NULL, 0, NULL, 0 }
153155
};
154156

155-
while ((opt = getopt_long(argc, argv, "hdkevf:c:p:groNt:nDZ:Uu",
157+
while ((opt = getopt_long(argc, argv, "hdkevf:c:p:gl:roNt:nDZ:Uu",
156158
long_options, NULL)) >= 0) {
157159

158160
switch(opt) {
@@ -191,6 +193,10 @@ static int parse_command_line(struct teamd_context *ctx,
191193
case 'g':
192194
ctx->debug++;
193195
break;
196+
case 'l':
197+
free(ctx->log_output);
198+
ctx->log_output = strdup(optarg);
199+
break;
194200
case 'r':
195201
ctx->force_recreate = true;
196202
break;
@@ -1494,6 +1500,16 @@ static int teamd_start(struct teamd_context *ctx, enum teamd_exit_code *p_ret)
14941500
/* Child */
14951501
}
14961502

1503+
ctx->log_output = ctx->log_output ? : getenv("TEAM_LOG_OUTPUT");
1504+
if (ctx->log_output) {
1505+
if (strcmp(ctx->log_output, "stdout") == 0)
1506+
daemon_log_use = DAEMON_LOG_STDOUT;
1507+
else if (strcmp(ctx->log_output, "stderr") == 0)
1508+
daemon_log_use = DAEMON_LOG_STDERR;
1509+
else if (strcmp(ctx->log_output, "syslog") == 0)
1510+
daemon_log_use = DAEMON_LOG_SYSLOG;
1511+
}
1512+
14971513
if (daemon_close_all(-1) < 0) {
14981514
teamd_log_err("Failed to close all file descriptors.");
14991515
daemon_retval_send(errno);

teamd/teamd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct teamd_context {
9999
enum teamd_command cmd;
100100
bool daemonize;
101101
unsigned int debug;
102+
char * log_output;
102103
bool force_recreate;
103104
bool take_over;
104105
bool no_quit_destroy;

0 commit comments

Comments
 (0)