nidas  v1.2-1520
Public Member Functions | Public Attributes | List of all members
nidas::util::LogConfig Class Reference

A configuration to enable or disable a matching set of log points. More...

#include <Logger.h>

Public Member Functions

bool matches (const LogContext &lc) const
 Return true if this config matches the given LogContext lc. More...
 
LogConfigparse (const std::string &text)
 Parse LogConfig settings from a string specifier, using comma-separated fields to assign to each of the config fields. More...
 
 LogConfig (const std::string &text="")
 Construct a default LogConfig which matches and enables every log point with level DEBUG or higher. More...
 

Public Attributes

std::string filename_match
 Apply this config to log points in filenames which contain the given string. More...
 
std::string function_match
 Apply this config to log points in functions which contain the given string. More...
 
std::string tag_match
 Apply this config to log points whose tags include this tag. More...
 
int line
 Apply this config to log points with the given line number. More...
 
int level
 For all matching log points, enable the log point if the log level is more severe (lower value) than this threshold level. More...
 
bool activate
 If true, then all matching log points will be enabled. More...
 

Detailed Description

A configuration to enable or disable a matching set of log points.

A LogConfig specifies which log points to match and whether to activate or disable them. The set of log points are matched by filename, function name, line number, and level. For example, all the log messages in a given file can be enabled with a LogConfig that sets filename_match to the filename and level to LOGGER_DEBUG. Methods within an object all include the class name in the function signature, so those can be enabled with a function_match set to the class name. The default LogConfig matches every log point with threshold DEBUG or lower, ie, not VERBOSE messages. File and function names are matched as substrings, so a function_match set to "Logger::" will match all methods of the Logger class.

Constructor & Destructor Documentation

LogConfig::LogConfig ( const std::string &  text = "")

Construct a default LogConfig which matches and enables every log point with level DEBUG or higher.

Then call parse() on the given text.

References parse().

Member Function Documentation

bool LogConfig::matches ( const LogContext lc) const
LogConfig & LogConfig::parse ( const std::string &  text)

Parse LogConfig settings from a string specifier, using comma-separated fields to assign to each of the config fields.

Throws std::runtime_error if the text fails to parse. Passing an empty string has no effect.

Return a reference to this LogConfig, so it can chained to construct a LogConfig from a string like so:

LogScheme().addConfig(LogConfig().parse(text))

Here are the fields:

  • <loglevelint>|<loglevelname>
  • tag=<tag>
  • file=<file>
  • function=<function>
  • line=<line>
  • enable|disable

This example enables all log messages for filenames which contain the string 'TwoD':

verbose,file=TwoD

Enable all debug messages in the core library:

debug,file=nidas/core

References activate, filename_match, function_match, level, line, parse_log_level(), and tag_match.

Referenced by LogConfig(), and nidas::core::NidasApp::parseLogConfig().

Member Data Documentation

bool nidas::util::LogConfig::activate

If true, then all matching log points will be enabled.

If false, any matching log points will be disabled.

Referenced by LogSchemeFromDOMElement(), and parse().

std::string nidas::util::LogConfig::filename_match

Apply this config to log points in filenames which contain the given string.

An empty string matches everything.

Referenced by LogSchemeFromDOMElement(), matches(), and parse().

std::string nidas::util::LogConfig::function_match

Apply this config to log points in functions which contain the given string.

An empty string matches everything.

Referenced by LogSchemeFromDOMElement(), matches(), and parse().

int nidas::util::LogConfig::level

For all matching log points, enable the log point if the log level is more severe (lower value) than this threshold level.

The default threshold includes all log levels.

Referenced by get_scheme(), LogSchemeFromDOMElement(), main(), matches(), parse(), PacketDecode::parseRunstring(), TeeTTy::run(), and nidas::core::NidasApp::setupLogScheme().

int nidas::util::LogConfig::line

Apply this config to log points with the given line number.

Really this only makes sense if filename_match is set also. The default of zero matches every line number.

Referenced by LogSchemeFromDOMElement(), and parse().

std::string nidas::util::LogConfig::tag_match

Apply this config to log points whose tags include this tag.

An empty string matches all tags.

Referenced by LogSchemeFromDOMElement(), matches(), and parse().


The documentation for this class was generated from the following files: