Skip to content

Commit

Permalink
Logfile location configurability.
Browse files Browse the repository at this point in the history
Fixes #555
  • Loading branch information
jshort committed Dec 21, 2022
1 parent 88fe46a commit d4716c2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ jobs:
no_output_timeout: 60m
- run:
name: Start Servers
command: sudo build/etserver --daemon; sudo build/etserver --port 2023 --serverfifo=/tmp/etserver.idpasskey.fifo2 --daemon; build/et -c "ls" --serverfifo=/tmp/etserver.idpasskey.fifo2 --logtostdout --verbose=9 --jumphost localhost --jport 2022 localhost:2023
command: sudo build/etserver --daemon; sleep 2; sudo build/etserver --port 2023 --serverfifo=/tmp/etserver.idpasskey.fifo2 --daemon; build/et -c "ls" --serverfifo=/tmp/etserver.idpasskey.fifo2 --logtostdout --verbose=9 --jumphost localhost --jport 2022 localhost:2023
- run:
name: Kill servers
command: sudo pkill etserver
- run:
name: Debug info/logs if failed
when: on_fail
command: ls -la /tmp/et*; sudo awk 'FNR==1 {print "XXXXXX", FILENAME, "XXXXXX"}{print}' /tmp/et*

workflows:
version: 2
Expand Down
1 change: 1 addition & 0 deletions etc/et.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ port = 2022
verbose = 0
silent = 0
logsize = 20971520
logdirectory = /tmp
telemetry = 1
16 changes: 9 additions & 7 deletions src/terminal/TerminalClientMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ int main(int argc, char** argv) {
("v,verbose", "Enable verbose logging",
cxxopts::value<int>()->default_value("0")) //
("k,keepalive", "Client keepalive duration in seconds",
cxxopts::value<int>()) //
("logtostdout", "Write log to stdout") //
("silent", "Disable logging") //
("N,no-terminal", "Do not create a terminal") //
("f,forward-ssh-agent", "Forward ssh-agent socket") //
cxxopts::value<int>()) //
("l,logdir", "Base directory for log files.",
cxxopts::value<std::string>()->default_value(tmpDir)) //
("logtostdout", "Write log to stdout") //
("silent", "Disable logging") //
("N,no-terminal", "Do not create a terminal") //
("f,forward-ssh-agent", "Forward ssh-agent socket") //
("ssh-socket", "The ssh-agent socket to forward",
cxxopts::value<std::string>()) //
("telemetry",
Expand Down Expand Up @@ -124,8 +126,8 @@ int main(int argc, char** argv) {
defaultConf.setGlobally(el::ConfigurationType::Enabled, "false");
}

LogHandler::setupLogFiles(&defaultConf, tmpDir, "etclient",
result.count("logtostdout"),
LogHandler::setupLogFiles(&defaultConf, result["logdir"].as<string>(),
"etclient", result.count("logtostdout"),
!result.count("logtostdout"));

el::Loggers::reconfigureLogger("default", defaultConf);
Expand Down
8 changes: 5 additions & 3 deletions src/terminal/TerminalMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ int main(int argc, char** argv) {
// Not used by etterminal but easylogging uses this flag under the hood
("v,verbose", "Enable verbose logging",
cxxopts::value<int>()->default_value("0")) //
("logtostdout", "Write log to stdout") //
("l,logdir", "Base directory for log files.",
cxxopts::value<std::string>()->default_value(GetTempDirectory())) //
("logtostdout", "Write log to stdout") //
("serverfifo",
"If set, connects to the etserver instance listening on the matching "
"fifo name", //
Expand Down Expand Up @@ -138,7 +140,7 @@ int main(int argc, char** argv) {
string username = string(ssh_get_local_username());
if (result.count("jump")) {
// etserver with --jump cannot write to the default log file(root)
LogHandler::setupLogFiles(&defaultConf, GetTempDirectory(),
LogHandler::setupLogFiles(&defaultConf, result["logdir"].as<string>(),
("etjump-" + username + "-" + id),
result.count("logtostdout"), false);
// Reconfigure default logger to apply settings above
Expand Down Expand Up @@ -167,7 +169,7 @@ int main(int argc, char** argv) {
}

// etserver with --idpasskey cannot write to the default log file(root)
LogHandler::setupLogFiles(&defaultConf, GetTempDirectory(),
LogHandler::setupLogFiles(&defaultConf, result["logdir"].as<string>(),
("etterminal-" + username + "-" + id),
result.count("logtostdout"), false);

Expand Down
17 changes: 15 additions & 2 deletions src/terminal/TerminalServerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ int main(int argc, char **argv) {
("daemon", "Daemonize the server") //
("cfgfile", "Location of the config file",
cxxopts::value<std::string>()->default_value("")) //
("logtostdout", "log to stdout") //
("l,logdir", "Base directory for log files.",
cxxopts::value<std::string>()) //
("logtostdout", "log to stdout") //
("pidfile", "Location of the pid file",
cxxopts::value<std::string>()->default_value(
"/var/run/etserver.pid")) //
Expand Down Expand Up @@ -77,6 +79,7 @@ int main(int argc, char **argv) {

int port = 0;
string bindIp = "";
string logDirectory = GetTempDirectory();
bool telemetry = true;
if (result.count("cfgfile")) {
// Load the config file
Expand Down Expand Up @@ -120,13 +123,19 @@ int main(int argc, char **argv) {
if (silent && atoi(silent) != 0) {
defaultConf.setGlobally(el::ConfigurationType::Enabled, "false");
}

// read log file size limit
const char *logsize = ini.GetValue("Debug", "logsize", NULL);
if (logsize && atoi(logsize) != 0) {
// make sure maxlogsize is a string of int value
maxlogsize = string(logsize);
}

// log file directory (TODO path validation and trailing slash cleanup)
const char *logdir = ini.GetValue("Debug", "logdirectory", NULL);
if (logdir) {
logDirectory = string(logdir);
}
} else {
STFATAL << "Invalid config file: " << cfgfilename;
}
Expand All @@ -149,6 +158,10 @@ int main(int argc, char **argv) {
telemetry = result["telemetry"].as<bool>();
}

if (result.count("logdir")) {
logDirectory = result["logdir"].as<string>();
}

GOOGLE_PROTOBUF_VERIFY_VERSION;
srand(1);

Expand All @@ -157,7 +170,7 @@ int main(int argc, char **argv) {
}

// Set log file for etserver process here.
LogHandler::setupLogFiles(&defaultConf, GetTempDirectory(), "etserver",
LogHandler::setupLogFiles(&defaultConf, logDirectory, "etserver",
result.count("logtostdout"),
!result.count("logtostdout"), maxlogsize);
// Reconfigure default logger to apply settings above
Expand Down

0 comments on commit d4716c2

Please sign in to comment.