Skip to content

Commit

Permalink
(maint) Log version and level at startup
Browse files Browse the repository at this point in the history
Logs pxp-agent version and configured log level as soon as logging is
configured. Clarifies when versions change in logging, which makes
debugging issues easier.
  • Loading branch information
MikaelSmith committed Jun 27, 2017
1 parent 5a10fea commit 3c75020
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
5 changes: 3 additions & 2 deletions exe/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ int main(int argc, char *argv[]) {
// Set up logging

try {
Configuration::Instance().setupLogging();
LOG_DEBUG("pxp-agent logging has been initialized");
std::string version, loglevel;
std::tie(version, loglevel) = Configuration::Instance().setupLogging();
LOG_INFO("pxp-agent {1} started at {2} level", version, loglevel);
} catch (const Configuration::Error& e) {
boost::nowide::cout << lth_loc::format("Failed to configure logging: {1}\n"
"Cannot start pxp-agent", e.what());
Expand Down
3 changes: 2 additions & 1 deletion lib/inc/pxp-agent/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class Configuration
/// Throw a Configuration::Error: in case of invalid the specified
/// log file is in a non-esixtent directory.
/// Other execeptions are propagated.
void setupLogging();
/// Returns version and log level.
std::pair<std::string, std::string> setupLogging();

/// Ensure all required values are valid. If necessary, expand
/// file paths to the expected format.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static void validateLogDirPath(const std::string& logfile)
}
}

void Configuration::setupLogging()
std::pair<std::string, std::string> Configuration::setupLogging()
{
logfile_ = HW::GetFlag<std::string>("logfile");
pcp_access_logfile_ = HW::GetFlag<std::string>("pcp-access-logfile");
Expand Down Expand Up @@ -268,14 +268,14 @@ void Configuration::setupLogging()
loglevel,
pcp_access_fstream_ptr_);

LOG_DEBUG("Logging configured");

if (!log_on_stdout) {
// Configure platform-specific things for file logging
// NB: we do that after setting up lth_log in order to log in
// case of failure
configure_platform_file_logging();
}

return std::make_pair(PXP_AGENT_VERSION, loglevel);
}

void Configuration::validate()
Expand Down
11 changes: 3 additions & 8 deletions locales/pxp-agent.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: pxp-agent 1.5.3\n"
"Project-Id-Version: pxp-agent 1.6.0\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
Expand Down Expand Up @@ -69,9 +69,9 @@ msgid ""
"Cannot start pxp-agent"
msgstr ""

#. debug
#. info
#: exe/main.cc
msgid "pxp-agent logging has been initialized"
msgid "pxp-agent {1} started at {2} level"
msgstr ""

#: exe/main.cc
Expand Down Expand Up @@ -172,11 +172,6 @@ msgstr ""
msgid "invalid log level: '{1}'"
msgstr ""

#. debug
#: lib/src/configuration.cc
msgid "Logging configured"
msgstr ""

#. info
#: lib/src/configuration.cc
msgid "Reopening the pxp-agent log file"
Expand Down

0 comments on commit 3c75020

Please sign in to comment.