nidas  v1.2-1520
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
nidas::util::LogScheme Class Reference

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< LogConfiglog_configs_v
 The type for the vector of LogConfigs returned by getConfigs(). More...
 

Public Member Functions

 LogScheme (const std::string &name="")
 Construct a LogScheme with no LogConfig entries and show fields set to "time,level,message". More...
 
LogSchemesetName (const std::string &name)
 LogScheme names must not be empty, so this method has no effect unless name.length() > 0. More...
 
const std::string & getName () const
 
LogSchemeclearConfigs ()
 Clear the set of LogConfig's in this scheme. More...
 
LogSchemeaddConfig (const LogConfig &lc)
 Push a new LogConfig onto the list of existing configs. More...
 
LogSchemeaddConfig (const std::string &config)
 Add a LogConfig constructed from string config. More...
 
LogSchemeaddFallback (const LogConfig &lc)
 Add a fallback LogConfig. More...
 
LogSchemeaddFallback (const std::string &config)
 
log_configs_v getConfigs ()
 Return a copy of the LogConfig instances added to this LogScheme. More...
 
int logLevel ()
 Return the highest level of log messages enabled in all the LogConfig instances added to this LogScheme. More...
 
LogSchemesetShowFields (const std::vector< LogField > &fields)
 Set the fields to show in log messages and their order. More...
 
LogSchemesetShowFields (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(). More...
 
std::string getShowFieldsString () const
 Return a comma-separated string describing the list of fields to be shown by this scheme. More...
 
bool parseParameter (const std::string &text)
 Parse a parameter setting using syntax <name>=. More...
 
void setParameter (const std::string &name, const std::string &value)
 Set a parameter for this scheme. More...
 
std::string getParameter (const std::string &name, const std::string &dvalue="")
 Return the string value of the parameter with name name. More...
 
template<typename 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. More...
 
std::string getEnvParameter (const std::string &name, const std::string &dvalue="")
 Return the value of the parameter. More...
 
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. More...
 
bool getShowLogPoints ()
 Return true if showLogPoints() is enabled. More...
 

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. More...
 
static std::string fieldToString (LogScheme::LogField lf)
 Convert a LogField to its lower-case string name. More...
 

Private Member Functions

void show_log_point (LogContext &lp)
 

Private Attributes

std::string _name
 
log_configs_v log_configs
 
std::vector< LogFieldlog_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
 

Detailed Description

A LogScheme is a vector of LogConfig's and the vector of fields to show in log messages.

Member Typedef Documentation

The type for the vector of LogConfigs returned by getConfigs().

Member Enumeration Documentation

Enumerator
NoneField 
ThreadField 
FunctionField 
FileField 
LevelField 
MessageField 
TimeField 
AllFields 

Constructor & Destructor Documentation

LogScheme::LogScheme ( const std::string &  name = "")
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().

Member Function Documentation

LogScheme & LogScheme::addConfig ( const LogConfig lc)

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.

Parameters
lcThe LogConfig to be added to this scheme.
Returns
This scheme.

References _fallbacks, and log_configs.

Referenced by addConfig(), LogSchemeFromDOMElement(), main(), and TeeTTy::run().

LogScheme & LogScheme::addConfig ( const std::string &  config)

Add a LogConfig constructed from string config.

Parameters
configText to be parsed into a LogConfig.
Returns
LogScheme&

References addConfig().

LogScheme & LogScheme::addFallback ( const LogConfig lc)

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.

Parameters
lc
Returns
LogScheme&

References _fallbacks, and log_configs.

Referenced by addFallback(), get_scheme(), 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().

std::string LogScheme::fieldToString ( LogScheme::LogField  lf)
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.

const std::string& nidas::util::LogScheme::getName ( ) const
inline
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.

Referenced by nidas::util::LoggerPrivate::reconfig().

bool nidas::util::LogScheme::getShowLogPoints ( )
inline

Return true if showLogPoints() is enabled.

References _showlogpoints.

Referenced by nidas::util::LogContext::LogContext().

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().

LogScheme& nidas::util::LogScheme::setName ( const std::string &  name)
inline

LogScheme names must not be empty, so this method has no effect unless name.length() > 0.

References _name.

Referenced by LogSchemeFromDOMElement().

void LogScheme::setParameter ( const std::string &  name,
const std::string &  value 
)

Set a parameter for this scheme.

References _parameters.

Referenced by parseParameter().

LogScheme & LogScheme::setShowFields ( const std::vector< LogField > &  fields)

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.

Parameters
fieldsA vector<LogField>.

References log_fields.

Referenced by LogSchemeFromDOMElement(), nidas::core::NidasApp::parseNext(), setShowFields(), and nidas::core::NidasApp::setupDaemonLogging().

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().

void LogScheme::show_log_point ( LogContext lp)
private
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, nidas::util::Logger::mutex, and show_log_point().

Referenced by nidas::core::NidasApp::parseNext().

LogScheme::LogField LogScheme::stringToField ( const std::string &  s)
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().

Friends And Related Function Documentation

friend class nidas::util::LogContext
friend
friend class nidas::util::Logger
friend
friend class nidas::util::LoggerPrivate
friend

Member Data Documentation

bool nidas::util::LogScheme::_fallbacks
private

Referenced by addConfig(), and addFallback().

std::string nidas::util::LogScheme::_name
private

Referenced by getName(), and setName().

std::map<std::string, std::string> nidas::util::LogScheme::_parameters
private
bool nidas::util::LogScheme::_showlogpoints
private

Referenced by getShowLogPoints(), and showLogPoints().

log_configs_v nidas::util::LogScheme::log_configs
private
std::vector<LogField> nidas::util::LogScheme::log_fields
private

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