From b1a7e0ff5e51cc68c8931130ade7264a51caad2d Mon Sep 17 00:00:00 2001 From: benrubson Date: Thu, 9 Mar 2017 14:07:58 +0100 Subject: [PATCH] Remove timestamp from loglines when syslog is used --- encfs/Error.cpp | 19 +++++++++++++++---- encfs/Error.h | 2 +- encfs/main.cpp | 11 +---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/encfs/Error.cpp b/encfs/Error.cpp index bbb90ce..94c5909 100644 --- a/encfs/Error.cpp +++ b/encfs/Error.cpp @@ -6,17 +6,28 @@ el::base::DispatchAction rlogAction = el::base::DispatchAction::NormalLog; Error::Error(const char *msg) : runtime_error(msg) {} -void initLogging(bool enable_debug) { - el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput); +void initLogging(bool enable_debug, bool is_daemon) { el::Configurations defaultConf; defaultConf.setToDefault(); - defaultConf.set(el::Level::Verbose, el::ConfigurationType::Format, - std::string("%datetime %level [%fbase:%line] %msg")); defaultConf.set(el::Level::Global, el::ConfigurationType::ToFile, "false"); + std::string prefix = "%datetime "; + std::string suffix = " [%fbase:%line]"; + if (is_daemon) { + prefix = ""; + encfs::rlogAction = el::base::DispatchAction::SysLog; + } + else { + el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput); + } if (!enable_debug) { + suffix = ""; defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "false"); } + else { + el::Loggers::setVerboseLevel(1); + } + defaultConf.setGlobally(el::ConfigurationType::Format, prefix + std::string("%level %msg") + suffix); el::Loggers::reconfigureLogger("default", defaultConf); } diff --git a/encfs/Error.h b/encfs/Error.h index bcedd43..3e54536 100644 --- a/encfs/Error.h +++ b/encfs/Error.h @@ -23,7 +23,7 @@ class Error : public std::runtime_error { } \ } while (0) -void initLogging(bool enable_debug = false); +void initLogging(bool enable_debug = false, bool is_daemon = false); // This can be changed to change log action between normal and syslog logging. // Not thread-safe, so any change must occur outside of threading context. diff --git a/encfs/main.cpp b/encfs/main.cpp index 77242b4..955a60f 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -491,11 +491,6 @@ void *encfs_init(fuse_conn_info *conn) { // set fuse connection options conn->async_read = true; - if (ctx->args->isDaemon) { - // Switch to using syslog. - encfs::rlogAction = el::base::DispatchAction::SysLog; - } - // if an idle timeout is specified, then setup a thread to monitor the // filesystem. if (ctx->args->idleTimeout > 0) { @@ -539,11 +534,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if (encfsArgs->isVerbose) { - el::Loggers::setVerboseLevel(1); - } - - encfs::initLogging(encfsArgs->isVerbose); + encfs::initLogging(encfsArgs->isVerbose, encfsArgs->isDaemon); VLOG(1) << "Root directory: " << encfsArgs->opts->rootDir; VLOG(1) << "Fuse arguments: " << encfsArgs->toString();