nidas v1.2.3
|
A LogScheme is a vector of LogConfig's and the vector of fields to show in log messages. More...
#include <Logger.h>
Public Types | |
enum | LogField { NoneField = 0 , ThreadField = 1 , FunctionField = 2 , FileField = 4 , LevelField = 8 , MessageField = 16 , TimeField = 32 , AllFields = 63 } |
typedef std::vector< LogConfig > | log_configs_v |
The type for the vector of LogConfigs returned by getConfigs(). | |
Public Member Functions | |
LogScheme (const std::string &name="") | |
Construct a LogScheme with no LogConfig entries and show fields set to "time,level,message". | |
LogScheme & | setName (const std::string &name) |
LogScheme names must not be empty, so this method has no effect unless name.length() > 0. | |
const std::string & | getName () const |
LogScheme & | clearConfigs () |
Clear the set of LogConfig's in this scheme. | |
LogScheme & | addConfig (const LogConfig &lc) |
Push a new LogConfig onto the list of existing configs. | |
LogScheme & | addConfig (const std::string &config) |
Add a LogConfig constructed from string config . | |
LogScheme & | addFallback (const LogConfig &lc) |
Add a fallback LogConfig. | |
LogScheme & | addFallback (const std::string &config) |
log_configs_v | getConfigs () |
Return a copy of the LogConfig instances added to this LogScheme. | |
int | logLevel () |
Return the highest level of log messages enabled in all the LogConfig instances added to this LogScheme. | |
LogScheme & | setShowFields (const std::vector< LogField > &fields) |
Set the fields to show in log messages and their order. | |
LogScheme & | setShowFields (const std::string &fields) |
Parse a comma-separated string of field names, with no spaces, into a vector of LogField values, and pass that to setShowFields(). | |
std::string | getShowFieldsString () const |
Return a comma-separated string describing the list of fields to be shown by this scheme. | |
bool | parseParameter (const std::string &text) |
Parse a parameter setting using syntax <name>=. | |
void | setParameter (const std::string &name, const std::string &value) |
Set a parameter for this scheme. | |
std::string | getParameter (const std::string &name, const std::string &dvalue="") |
Return the string value of the parameter with name name . | |
template<typename T > | |
T | getParameterT (const std::string &name, const T &dvalue=T()) |
Lookup a parameter with name name in a LogScheme and convert the value to the type of the dvalue parameter. | |
std::string | getEnvParameter (const std::string &name, const std::string &dvalue="") |
Return the value of the parameter. | |
void | showLogPoints (bool show) |
If show is true, then all the known log points will be listed in log messages, and all future log points will be logged as they are created. | |
bool | getShowLogPoints () |
Return true if showLogPoints() is enabled. | |
Static Public Member Functions | |
static LogField | stringToField (const std::string &s) |
Convert the name of a log information field to its enum, such as Logger::ThreadField. | |
static std::string | fieldToString (LogScheme::LogField lf) |
Convert a LogField to its lower-case string name. | |
Private Member Functions | |
void | show_log_point (const LogContextState &lp) const |
Log a message about the existence and state of the given LogContext @lp. | |
Private Attributes | |
std::string | _name |
log_configs_v | log_configs |
std::vector< LogField > | log_fields |
std::map< std::string, std::string > | _parameters |
bool | _showlogpoints |
bool | _fallbacks |
Friends | |
class | nidas::util::LoggerPrivate |
class | nidas::util::Logger |
class | nidas::util::LogContext |
typedef std::vector<LogConfig> nidas::util::LogScheme::log_configs_v |
The type for the vector of LogConfigs returned by getConfigs().
|
explicit |
Construct a LogScheme with no LogConfig entries and show fields set to "time,level,message".
Name is set to name
. A scheme with no configs does not enable any log messages. This is not the LogScheme used by default if an application does not setup the logging configuration itself. See Logging Configuration Schemes. A LogScheme can have an empty name, but there can be only one scheme with any given name installed through setScheme() and updateScheme().
Push a new LogConfig onto the list of existing configs.
When this scheme is active, this config will be applied to any log points which it matches. For example, if the activate
flag of this config is false, then any matching log points will be disabled. The configurations are cumulative, so the latest config on the list will take precedence. For example, if an earlier config enables all points, then further configs can disable a subset of log points.
If this scheme had any fallback configs, they will be erased first before adding this config.
lc | The LogConfig to be added to this scheme. |
References _fallbacks, and log_configs.
Referenced by addConfig(), and nidas::core::NidasApp::parseLogConfig().
LogScheme & LogScheme::addConfig | ( | const std::string & | config | ) |
Add a LogConfig constructed from string config
.
config | Text to be parsed into a LogConfig. |
References addConfig().
Add a fallback LogConfig.
Since a LogScheme does not enable any logs if it has no configs, it can be useful to add configs which will only be used as a fallback, when no other configs are added. This method adds a LogConfig as a fallback only if the scheme has no configs yet or the existing configs were also added as fallbacks. When a config is added with addConfig(), it replaces all the fallback configs.
lc |
References _fallbacks, and log_configs.
Referenced by addFallback(), nidas::core::NidasApp::parseNext(), and nidas::core::NidasApp::setupLogScheme().
LogScheme & LogScheme::addFallback | ( | const std::string & | config | ) |
References addFallback().
LogScheme & LogScheme::clearConfigs | ( | ) |
Clear the set of LogConfig's in this scheme.
An empty set of LogConfig's disables all logging for this scheme.
References log_configs.
Referenced by main().
|
static |
Convert a LogField to its lower-case string name.
Returns "none" if the LogField is NoneField or invalid.
Referenced by getShowFieldsString().
LogScheme::log_configs_v LogScheme::getConfigs | ( | ) |
Return a copy of the LogConfig instances added to this LogScheme.
References log_configs.
std::string LogScheme::getEnvParameter | ( | const std::string & | name, |
const std::string & | dvalue = "" ) |
Return the value of the parameter.
If the parameter has not been set, then look for a value in the environment, and otherwise return the default.
References _parameters.
|
inline |
References _name.
std::string LogScheme::getParameter | ( | const std::string & | name, |
const std::string & | dvalue = "" ) |
Return the string value of the parameter with name name
.
If the parameter has not been set in this LogScheme, then return the default value dvalue
. See getParameterT() to retrieve the string value as a particular type.
References _parameters.
Referenced by getParameterT(), and nidas::core::SampleTracer::SampleTracer().
std::string LogScheme::getShowFieldsString | ( | ) | const |
Return a comma-separated string describing the list of fields to be shown by this scheme.
References fieldToString(), and log_fields.
|
inline |
Return true if showLogPoints() is enabled.
References _showlogpoints.
int LogScheme::logLevel | ( | ) |
Return the highest level of log messages enabled in all the LogConfig instances added to this LogScheme.
For basic configurations, where a single LogConfig just enables all messages of a certain level, this method returns that level. In more complicated configurations, there may be only a few log messages enabled at the returned level, but there will be no messages enabled at a higher level.
Since a LogScheme with no configs enables no messages, it returns LOGGER_NONE.
References nidas::util::LoggerPrivate::DEFAULT_LOGLEVEL, log_configs, and nidas::util::LOGGER_NONE.
bool LogScheme::parseParameter | ( | const std::string & | text | ) |
Parse a parameter setting using syntax <name>=.
References setParameter().
Referenced by nidas::core::NidasApp::parseNext().
|
inline |
void LogScheme::setParameter | ( | const std::string & | name, |
const std::string & | value ) |
LogScheme & LogScheme::setShowFields | ( | const std::string & | fields | ) |
Parse a comma-separated string of field names, with no spaces, into a vector of LogField values, and pass that to setShowFields().
Throw std::runtime_error if the string fails to parse.
Valid fields: thread,function,file,level,time,message
References NoneField, setShowFields(), and stringToField().
Set the fields to show in log messages and their order.
The fields in fields
will be shown in the same order as in the vector. Any fields not included will be omitted.
fields | A vector<LogField>. |
References log_fields.
Referenced by nidas::core::NidasApp::parseNext(), setShowFields(), and nidas::core::NidasApp::setupDaemonLogging().
|
private |
Log a message about the existence and state of the given LogContext @lp.
Like other log messages, this one happens without a lock of the logger_mutex.
References show_point.
Referenced by showLogPoints().
void LogScheme::showLogPoints | ( | bool | show | ) |
If show
is true, then all the known log points will be listed in log messages, and all future log points will be logged as they are created.
Disable this logging by passing false.
References _showlogpoints, log_points, and show_log_point().
Referenced by nidas::core::NidasApp::parseNext().
|
static |
Convert the name of a log information field to its enum, such as Logger::ThreadField.
Returns NoneField if the name is not recognized.
References NoneField.
Referenced by setShowFields().
|
friend |
|
friend |
|
friend |
|
private |
Referenced by addConfig(), and addFallback().
|
private |
Referenced by getEnvParameter(), getParameter(), and setParameter().
|
private |
Referenced by getShowLogPoints(), and showLogPoints().
|
private |
Referenced by addConfig(), addFallback(), clearConfigs(), getConfigs(), and logLevel().
|
private |
Referenced by getShowFieldsString(), and setShowFields().