syncevo-dbus-server: log only to syslog by default
The new default is to log error messages to syslog. Command line options can increase (or reduce) verbosity and choose whether stdout and/or syslog shall be active: -d, --duration=seconds/'unlimited' Shut down automatically when idle for this duration -v, --verbosity=level Choose amount of output, 0 = no output, 1 = errors, 2 = info, 3 = debug; default is 1. -o, --stdout Enable printing to stdout (result of operations) and stderr (errors/info/debug). -s, --no-syslog Disable printing to syslog. To get the same behavior as before when debugging via the Python scripts, "--no-syslog --stdout --verbosity=3" is passed to syncevo-dbus-server when started via Python.
This commit is contained in:
parent
91c4960f1e
commit
9700079e61
|
@ -83,8 +83,18 @@ int main(int argc, char **argv, char **envp)
|
|||
try {
|
||||
gchar *durationString = NULL;
|
||||
int duration = 600;
|
||||
int logLevel = 1;
|
||||
gboolean stdoutEnabled = false;
|
||||
gboolean syslogEnabled = true;
|
||||
static GOptionEntry entries[] = {
|
||||
{ "duration", 'd', 0, G_OPTION_ARG_STRING, &durationString, "Shut down automatically when idle for this duration", "seconds/'unlimited'" },
|
||||
{ "verbosity", 'v', 0, G_OPTION_ARG_INT, &logLevel,
|
||||
"Choose amount of output, 0 = no output, 1 = errors, 2 = info, 3 = debug; default is 1.",
|
||||
"level" },
|
||||
{ "stdout", 'o', 0, G_OPTION_ARG_NONE, &stdoutEnabled,
|
||||
"Enable printing to stdout (result of operations) and stderr (errors/info/debug).",
|
||||
NULL },
|
||||
{ "no-syslog", 's', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &syslogEnabled, "Disable printing to syslog.", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
GErrorCXX gerror;
|
||||
|
@ -98,6 +108,23 @@ int main(int argc, char **argv, char **envp)
|
|||
if (durationString && !parseDuration(duration, durationString)) {
|
||||
SE_THROW(StringPrintf("invalid parameter value '%s' for --duration/-d: must be positive number of seconds or 'unlimited'", durationString));
|
||||
}
|
||||
Logger::Level level;
|
||||
switch (logLevel) {
|
||||
case 0:
|
||||
level = Logger::NONE;
|
||||
break;
|
||||
case 1:
|
||||
level = Logger::ERROR;
|
||||
break;
|
||||
case 2:
|
||||
level = Logger::INFO;
|
||||
break;
|
||||
case 3:
|
||||
level = Logger::DEBUG;
|
||||
break;
|
||||
default:
|
||||
SE_THROW(StringPrintf("invalid parameter value %d for --debug: must be one of 0, 1, 2 or 3", logLevel));
|
||||
}
|
||||
|
||||
// Temporarily set G_DBUS_DEBUG. Hopefully GIO will read and
|
||||
// remember it, because we don't want to keep it set
|
||||
|
@ -114,22 +141,15 @@ int main(int argc, char **argv, char **envp)
|
|||
setvbuf(stderr, NULL, _IONBF, 0);
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
const char *debugVar(getenv(debugEnv));
|
||||
const bool debugEnabled(debugVar && *debugVar);
|
||||
|
||||
// TODO: redirect output *and* log it via syslog?!
|
||||
boost::shared_ptr<LoggerBase> logger;
|
||||
if (!gdbus) {
|
||||
logger.reset((true || debugEnabled) ?
|
||||
static_cast<LoggerBase *>(new LogRedirect(true)) :
|
||||
static_cast<LoggerBase *>(new LoggerSyslog(execName)));
|
||||
// Redirect output and optionally log to syslog.
|
||||
LogRedirect redirect(true);
|
||||
redirect.setLevel(stdoutEnabled ? level : Logger::NONE);
|
||||
std::auto_ptr<LoggerBase> syslogger;
|
||||
if (syslogEnabled && level > Logger::NONE) {
|
||||
syslogger.reset(new LoggerSyslog(execName));
|
||||
syslogger->setLevel(level);
|
||||
}
|
||||
|
||||
// make daemon less chatty - long term this should be a command line option
|
||||
LoggerBase::instance().setLevel(debugEnabled ?
|
||||
LoggerBase::DEBUG :
|
||||
LoggerBase::INFO);
|
||||
|
||||
// syncevo-dbus-server should hardly ever produce output that
|
||||
// is relevant for end users, so include the somewhat cryptic
|
||||
// process name for developers in this process, and not in
|
||||
|
|
|
@ -78,6 +78,11 @@ class Logger
|
|||
* - everything else: DEBUG
|
||||
*/
|
||||
typedef enum {
|
||||
/**
|
||||
* no error messages printed
|
||||
*/
|
||||
NONE = -1,
|
||||
|
||||
/**
|
||||
* only error messages printed
|
||||
*/
|
||||
|
|
|
@ -57,7 +57,7 @@ except ImportError:
|
|||
DBusGMainLoop(set_as_default=True)
|
||||
|
||||
debugger = os.environ.get("TEST_DBUS_GDB", None) and "gdb" or ""
|
||||
server = ["syncevo-dbus-server"]
|
||||
server = "syncevo-dbus-server --no-syslog --stdout --verbosity=3".split()
|
||||
monitor = ["dbus-monitor"]
|
||||
# primarily for XDG files, but also other temporary files
|
||||
xdg_root = "temp-test-dbus"
|
||||
|
@ -506,7 +506,7 @@ class DBusUtil(Timeout):
|
|||
gdbinit = ['-x', os.path.join(os.environ.get("HOME"), ".gdbinit")]
|
||||
else:
|
||||
gdbinit = []
|
||||
DBusUtil.pserver = subprocess.Popen([debugger] + gdbinit + server,
|
||||
DBusUtil.pserver = subprocess.Popen([debugger] + gdbinit + ['--args'] + server,
|
||||
env=env)
|
||||
|
||||
while not bus.name_has_owner('org.syncevolution'):
|
||||
|
@ -1422,7 +1422,7 @@ class TestDBusServerTerm(DBusUtil, unittest.TestCase):
|
|||
|
||||
def testSingleton(self):
|
||||
"""TestDBusServerTerm.testSingleton - a second instance of syncevo-dbus-server must terminate right away"""
|
||||
dbus = subprocess.Popen([ 'syncevo-dbus-server' ],
|
||||
dbus = subprocess.Popen('syncevo-dbus-server --no-syslog --stdout'.split(),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
(out, err) = dbus.communicate()
|
||||
|
|
Loading…
Reference in New Issue