Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging #296

Merged
merged 2 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions encfs/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion encfs/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions encfs/encfs.pod
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Normally these logging messages are disabled and have no effect. It is
recommended that you run in foreground (B<-f>) mode when running with verbose
enabled.

=item B<-t>, B<--syslogtag>

This option allows to set the syslog tag which will be used when messages are
logged via syslog. By default the syslog tag is set to B<encfs>.

=item B<-s>

The B<-s> (I<single threaded>) option causes B<EncFS> to run in single threaded
Expand Down
21 changes: 10 additions & 11 deletions encfs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct EncFS_Args {
int idleTimeout; // 0 == idle time in minutes to trigger unmount
const char *fuseArgv[MaxFuseArgs];
int fuseArgc;
std::string syslogTag; // syslog tag to use when logging using syslog

std::shared_ptr<EncFS_Opts> opts;

Expand Down Expand Up @@ -190,6 +191,7 @@ static bool processArgs(int argc, char *argv[],
out->isVerbose = false;
out->idleTimeout = 0;
out->fuseArgc = 0;
out->syslogTag = "encfs";
out->opts->idleTracking = false;
out->opts->checkKey = true;
out->opts->forceDecode = false;
Expand Down Expand Up @@ -225,6 +227,7 @@ static bool processArgs(int argc, char *argv[],
{"extpass", 1, 0, 'p'}, // external password program
// {"single-thread", 0, 0, 's'}, // single-threaded mode
{"stdinpass", 0, 0, 'S'}, // read password from stdin
{"syslogtag", 1, 0, 't'}, // syslog tag
{"annotate", 0, 0,
LONG_OPT_ANNOTATE}, // Print annotation lines to stderr
{"nocache", 0, 0, LONG_OPT_NOCACHE}, // disable caching
Expand All @@ -247,8 +250,9 @@ static bool processArgs(int argc, char *argv[],
// 'm' : mount-on-demand
// 'S' : password from stdin
// 'o' : arguments meant for fuse
// 't' : syslog tag
int res =
getopt_long(argc, argv, "HsSfvdmi:o:", long_options, &option_index);
getopt_long(argc, argv, "HsSfvdmi:o:t:", long_options, &option_index);

if (res == -1) break;

Expand All @@ -265,6 +269,9 @@ static bool processArgs(int argc, char *argv[],
case 'S':
out->opts->useStdin = true;
break;
case 't':
out->syslogTag = optarg;
break;
case LONG_OPT_ANNOTATE:
out->opts->annotate = true;
break;
Expand Down Expand Up @@ -491,11 +498,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) {
Expand Down Expand Up @@ -539,11 +541,8 @@ 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);
ELPP_INITIALIZE_SYSLOG(encfsArgs->syslogTag.c_str(), 0, 0);

VLOG(1) << "Root directory: " << encfsArgs->opts->rootDir;
VLOG(1) << "Fuse arguments: " << encfsArgs->toString();
Expand Down