Skip to content

Commit

Permalink
Added a string representation for log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
ereOn committed Dec 31, 2018
1 parent 49df714 commit feb3951
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/freelan/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ bool parse_options(fscp::logger& logger, int argc, char** argv, cli_configuratio
if (configuration.debug)
{
logger.set_level(fscp::log_level::trace);
logger(fscp::log_level::trace) << "Debug output enabled.";
}

setup_configuration(logger, configuration.fl_configuration, vm);
Expand Down Expand Up @@ -474,6 +475,8 @@ void run(fscp::logger& logger, const cli_configuration& configuration, int& exit

fl::core core(io_service, configuration.fl_configuration);

logger(fscp::log_level::information) << "Setting core logging level to: " << logger.level() << ".";

core.set_log_level(logger.level());
core.set_log_callback(log_func);

Expand Down
29 changes: 29 additions & 0 deletions libs/fscp/include/fscp/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,35 @@ namespace fscp
fatal /**< \brief The fatal log level. */
};

/**
* \brief Output a log level as its string representation.
* \param os The output stream.
* \param lvl The log level.
* \return os.
*/
inline std::ostream& operator<<(std::ostream& os, log_level lvl)
{
switch (lvl)
{
case log_level::trace:
return os << "trace";
case log_level::debug:
return os << "debug";
case log_level::information:
return os << "information";
case log_level::important:
return os << "important";
case log_level::warning:
return os << "warning";
case log_level::error:
return os << "error";
case log_level::fatal:
return os << "fatal";
default:
return os << "<unspecified log level>";
}
}

/**
* \brief A null logger stream.
*/
Expand Down

0 comments on commit feb3951

Please sign in to comment.