2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 01:51:26 +00:00

vlog: Add vlog/close command.

Requested-by: P R Dinesh
Requested-at: https://github.com/openvswitch/ovs/pull/94
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
This commit is contained in:
Ben Pfaff 2016-02-03 13:41:34 -08:00
parent 922fed065e
commit 063801288e
7 changed files with 125 additions and 6 deletions

2
NEWS
View File

@ -12,6 +12,8 @@ Post-v2.5.0
Old 'other_config:n-dpdk-rxqs' is no longer supported.
- ovs-benchmark: This utility has been removed due to lack of use and
bitrot.
- ovs-appctl:
* New "vlog/close" command.
v2.5.0 - xx xxx xxxx

View File

@ -54,9 +54,14 @@ Lists the supported logging modules and their current levels.
.IP "\fBvlog/list-pattern\fR"
Lists logging patterns used for each destination.
.
.IP "\fBvlog/close\fR"
Causes \fB\*(PN\fR to close its log file, if it is open. (Use
\fBvlog/reopen\fR to reopen it later.)
.
.IP "\fBvlog/reopen\fR"
Causes \fB\*(PN\fR to close and reopen its log file. (This is useful
after rotating log files, to cause a new log file to be used.)
Causes \fB\*(PN\fR to close its log file, if it is open, and then
reopen it. (This is useful after rotating log files, to cause a new
log file to be used.)
.IP
This has no effect unless \fB\*(PN\fR was invoked with the
\fB\-\-log\-file\fR option.

View File

@ -677,6 +677,28 @@ vlog_unixctl_reopen(struct unixctl_conn *conn, int argc OVS_UNUSED,
}
}
static void
vlog_unixctl_close(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
{
ovs_mutex_lock(&log_file_mutex);
if (log_fd >= 0) {
close(log_fd);
log_fd = -1;
async_append_destroy(log_writer);
log_writer = NULL;
struct vlog_module *mp;
LIST_FOR_EACH (mp, list, &vlog_modules) {
update_min_level(mp);
}
}
ovs_mutex_unlock(&log_file_mutex);
unixctl_command_reply(conn, NULL);
}
static void
set_all_rate_limits(bool enable)
{
@ -771,6 +793,8 @@ vlog_init(void)
0, INT_MAX, vlog_disable_rate_limit, NULL);
unixctl_command_register("vlog/reopen", "", 0, 0,
vlog_unixctl_reopen, NULL);
unixctl_command_register("vlog/close", "", 0, 0,
vlog_unixctl_close, NULL);
ovs_rwlock_rdlock(&pattern_rwlock);
print_syslog_target_deprecation = syslog_fd >= 0;

View File

@ -1,5 +1,5 @@
# Copyright (c) 2011, 2012, 2013 Nicira, Inc.
# Copyright (c) 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -241,6 +241,8 @@ class Vlog(object):
ovs.unixctl.command_register("vlog/reopen", "", 0, 0,
Vlog._unixctl_vlog_reopen, None)
ovs.unixctl.command_register("vlog/close", "", 0, 0,
Vlog._unixctl_vlog_close, None)
ovs.unixctl.command_register("vlog/set", "spec", 1, sys.maxsize,
Vlog._unixctl_vlog_set, None)
ovs.unixctl.command_register("vlog/list", "", 0, 0,
@ -389,6 +391,13 @@ class Vlog(object):
else:
conn.reply("Logging to file not configured")
@staticmethod
def _unixctl_vlog_close(conn, unused_argv, unused_aux):
if Vlog.__log_file:
logger = logging.getLogger("file")
logger.removeHandler(Vlog.__file_handler)
conn.reply(None)
@staticmethod
def _unixctl_vlog_set(conn, argv, unused_aux):
for arg in argv:

View File

@ -102,6 +102,7 @@ The available commands are:
help
log [[arg ...]]
version
vlog/close
vlog/list
vlog/reopen
vlog/set spec

View File

@ -255,6 +255,80 @@ AT_CHECK([sed 's/.*|//' log], [0], [dnl
])
AT_CLEANUP
AT_SETUP([vlog - vlog/close - C])
on_exit 'kill `cat test-unixctl.pid`'
AT_CAPTURE_FILE([log])
AT_CAPTURE_FILE([log.old])
AT_CHECK([ovstest test-unixctl --log-file=`pwd`/log --pidfile --detach],
[0], [], [stderr])
AT_CHECK([vlog_filt stderr], [0], [opened log file
])
AT_CHECK([APPCTL -t test-unixctl log message])
AT_CHECK([APPCTL -t test-unixctl log message2])
# After closing the log file, message3 won't appear anywhere.
AT_CHECK([APPCTL -t test-unixctl vlog/close])
mv log log.old
AT_CHECK([APPCTL -t test-unixctl log message3])
# Closing the log file again is harmless.
AT_CHECK([APPCTL -t test-unixctl vlog/close])
AT_CHECK([APPCTL -t test-unixctl log message4])
# After reopening the log file, further messages start appearing again.
AT_CHECK([APPCTL -t test-unixctl vlog/reopen])
AT_CHECK([APPCTL -t test-unixctl log message5])
AT_CHECK([APPCTL -t test-unixctl exit])
AT_CHECK([vlog_filt log.old], [0], [dnl
opened log file
Entering run loop.
message
message2
])
AT_CHECK([vlog_filt log], [0], [dnl
opened log file
message5
])
AT_CLEANUP
AT_SETUP([vlog - vlog/close - Python])
AT_SKIP_IF([test $HAVE_PYTHON = no])
on_exit 'kill `cat test-unixctl.py.pid`'
AT_CAPTURE_FILE([log])
AT_CAPTURE_FILE([log.old])
AT_CHECK([$PYTHON $srcdir/test-unixctl.py --log-file=`pwd`/log --pidfile --detach])
AT_CHECK([APPCTL -t test-unixctl.py log message])
AT_CHECK([APPCTL -t test-unixctl.py log message2])
# After closing the log file, message3 won't appear anywhere.
AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
mv log log.old
AT_CHECK([APPCTL -t test-unixctl.py log message3])
# Closing the log file again is harmless.
AT_CHECK([APPCTL -t test-unixctl.py vlog/close])
AT_CHECK([APPCTL -t test-unixctl.py log message4])
# After reopening the log file, further messages start appearing again.
AT_CHECK([APPCTL -t test-unixctl.py vlog/reopen])
AT_CHECK([APPCTL -t test-unixctl.py log message5])
AT_CHECK([APPCTL -t test-unixctl.py exit])
AT_CHECK([sed 's/.*|//' log.old], [0], [dnl
Entering run loop.
message
message2
])
AT_CHECK([sed 's/.*|//' log], [0], [dnl
message5
])
AT_CLEANUP
AT_SETUP([vlog - vlog/set and vlog/list - C])
on_exit 'kill `cat test-unixctl.pid`'

View File

@ -265,10 +265,14 @@ Sets the RFC5424 facility of the log message. \fIfacility\fR can be one of
\fBlocal2\fR, \fBlocal3\fR, \fBlocal4\fR, \fBlocal5\fR, \fBlocal6\fR or
\fBlocal7\fR.
.
.IP "\fBvlog/close\fR"
Causes the daemon to close its log file, if it is open. (Use
\fBvlog/reopen\fR to reopen it later.)
.
.IP "\fBvlog/reopen\fR"
Causes the daemon to close and reopen its log file. (This
is useful after rotating log files, to cause a new log file to be
used.)
Causes the daemon to close its log file, if it is open, and then
reopen it. (This is useful after rotating log files, to cause a new
log file to be used.)
.IP
This has no effect if the target application was not invoked with the
\fB\-\-log\-file\fR option.