LSSTApplications
10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
|
a place to record messages and descriptions of the state of processing. More...
#include <Log.h>
Public Member Functions | |
Log (const int threshold=INFO, const std::string &name="") | |
Log (const std::list< boost::shared_ptr< LogDestination > > &destinations, const lsst::daf::base::PropertySet &preamble, const std::string &name="", const int threshold=INFO, bool defaultShowAll=false) | |
Log (const Log &parent, const std::string &childName, int threshold=INHERIT_THRESHOLD) | |
Log (const Log &that) | |
virtual | ~Log () |
Log & | operator= (const Log &that) |
const std::string & | getName () const |
int | getThreshold () const |
void | setThreshold (int threshold) |
bool | sends (int importance) const |
void | resetThreshold () |
void | setThresholdFor (const std::string &name, int threshold) |
int | getThresholdFor (const std::string &name) const |
bool | willShowAll () const |
void | setShowAll (bool yesno) |
void | resetShowAll () |
template<class T > | |
void | addPreambleProperty (const std::string &name, const T &val) |
template<class T > | |
void | setPreambleProperty (const std::string &name, const T &val) |
Log * | createChildLog (const std::string &childName, int threshold=INHERIT_THRESHOLD) const |
void | log (int importance, const std::string &message, const lsst::daf::base::PropertySet &properties) |
template<class T > | |
void | log (int importance, const std::string &message, const std::string &name, const T &val) |
template<class T > | |
void | log (int importance, const std::string &message, const RecordProperty< T > &prop) |
void | log (int importance, const std::string &message) |
void | log (int importance, const boost::format &message) |
void | logdebug (const std::string &message, const lsst::daf::base::PropertySet &properties) |
template<class T > | |
void | logdebug (const std::string &message, const std::string &name, const T &val) |
template<class T > | |
void | logdebug (const std::string &message, const RecordProperty< T > &prop) |
void | logdebug (const std::string &message) |
void | logdebug (const boost::format &message) |
void | info (const std::string &message, const lsst::daf::base::PropertySet &properties) |
template<class T > | |
void | info (const std::string &message, const std::string &name, const T &val) |
template<class T > | |
void | info (const std::string &message, const RecordProperty< T > &prop) |
void | info (const std::string &message) |
void | info (const boost::format &message) |
void | warn (const std::string &message, const lsst::daf::base::PropertySet &properties) |
template<class T > | |
void | warn (const std::string &message, const std::string &name, const T &val) |
template<class T > | |
void | warn (const std::string &message, const RecordProperty< T > &prop) |
void | warn (const std::string &message) |
void | warn (const boost::format &message) |
void | fatal (const std::string &message, const lsst::daf::base::PropertySet &properties) |
template<class T > | |
void | fatal (const std::string &message, const std::string &name, const T &val) |
template<class T > | |
void | fatal (const std::string &message, const RecordProperty< T > &prop) |
void | fatal (const std::string &message) |
void | fatal (const boost::format &message) |
void | format (int importance, const char *fmt,...) |
void | debugf (const char *fmt,...) |
void | infof (const char *fmt,...) |
void | warnf (const char *fmt,...) |
void | fatalf (const char *fmt,...) |
void | send (const LogRecord &record) |
void | addDestination (std::ostream &destination, int threshold) |
void | addDestination (std::ostream &destination, int threshold, const boost::shared_ptr< LogFormatter > &formatter) |
void | addDestination (const boost::shared_ptr< LogDestination > &destination) |
const lsst::daf::base::PropertySet & | getPreamble () |
void | markPersistent () |
void | printThresholds (std::ostream &out) |
void | reset () |
Static Public Member Functions | |
static Log & | getDefaultLog () |
static void | createDefaultLog (const std::list< boost::shared_ptr< LogDestination > > &destinations, const lsst::daf::base::PropertySet &preamble, const std::string &name="", const int threshold=INFO) |
static void | closeDefaultLog () |
Static Public Attributes | |
static const int | DEBUG |
static const int | INFO |
static const int | WARN |
static const int | INHERIT_THRESHOLD |
static const int | FATAL |
Protected Member Functions | |
void | _send (int threshold, int importance, const char *fmt, va_list ap) |
void | _format (int importance, const char *fmt, va_list ap) |
Static Protected Member Functions | |
static void | setDefaultLog (Log *deflog) |
Protected Attributes | |
boost::shared_ptr < threshold::Memory > | _thresholds |
std::list< boost::shared_ptr < LogDestination > > | _destinations |
lsst::daf::base::PropertySet::Ptr | _preamble |
Static Protected Attributes | |
static Log * | defaultLog |
static const std::string | _sep |
Private Member Functions | |
void | completePreamble () |
Private Attributes | |
int | _threshold |
boost::shared_ptr< bool > | _defShowAll |
boost::shared_ptr< bool > | _myShowAll |
std::string | _name |
a place to record messages and descriptions of the state of processing.
This class is the centerpiece of the logging framework. It allows modules to record plain text statements about what is happening (including errors, warnings, status information, and debugging messages) as well as typed data delivered as named properties. It allows users to conveniently tag their messages with a hierarchical label that can indicate where in the application the message originates. Messages sent to a Log can be routed to multiple destinations, such as to the terminal screen, to a file and to the Event system, all simultaneously. Messages are also tagged with an importance or "loudness" level, and Logs control their verbosity via importance thresholds. If a message's importance level is less than the Log's threshold, it will not be recorded. This allows applications and modules to selectively turn on and off, say, debugging messages of which there may be a great number. Thresholds are enforced in a way to minimize the impact of unrecorded messages on overall performance, so debugging messages can remain permanently compiled into the code. Finally, the different streams that receive log messages can have their own thresholds set as well; this allows one to, for example, send more messages to a file than to the screen.
Logs used by an application are organized into a hierarchy. Applications normally get the root Log via the static method Log::getDefaultLog(). This log by default is configured to print messages to the screen (although a production application will typically replace the default Log with one that sends messages elsewhere). Alternatively, an application can configure its own root Log via the Log constructors, or with the convenience subclasses, ScreenLog and DualLog (used to send messages to both the screen and a file). It is possible to have multiple, independently-configured Log hierarchies, but it is intended that one is sufficient for an entire application.
A root Log has an empty string name associated with it. A module will usually create a "child" or "descendent" Log object to send its messages to, giving it a period-delimited name and a importance threshold:
Log mylog(Log::getDefaultLog(), "myapp.mymod", Log::INFO);
or
scoped_ptr<Log> mylog(getDefaultLog().createChildLog("myapp.mymod", Log::INFO));
The new log will have the name "myapp.mymod" and allows messages at least as "loud" as Log::INFO. The defined levels, FATAL, WARN, INFO, DEBUG (set to 20, 10, 0, -10, respectively) are conventional notions to encourage uniformity of levels across modules. The sub-names between the periods indicate the levels of the Logging hierarchy. Note that once a threshold is set for a log at a particular level, it is remembered even after that log is deleted; when anther log is created with that name, its previous threshold is preserved. If no threshold is provided, it will default to that of its parents log. Furthermore, setting the threshold for a parent automatically updates the threshold for all of its descendents that have not otherwise set the threshold. For example,
Log root = Log::getDefaultLog(); // the root log; name is an empty string Log applog(root, "myapp"); // myapp: a child log Log *modlog = applog.createChildLog("mymod", Log::WARN); // myapp.mymod: a quieter grandchild log delete modlog; modlog = applog.createChildLog("mymod") // still set to Log::WARN
root.setThreshold(log::DEBUG); // root and applog now set to Log::DEBUG modlog.resetThreshold(); // modlog now also set to Log::DEBUG
As you can see in the example, names are set relative to their parent. That is, when we use a log called "myapp" to create a child called "mymod", the full name is "myapp.mymod". This allows a Log to be made a member of a class and given a name without knowing the context in which the class is being used. Note that it is not necessary to create logs at intervening levels; the first example above, shows us directly creating a "grandchild" from the root Log.
Simple text log messages can be recorded with the log() functions:
mylog.log(Log::WARN, "Skipping initialization"); mylog.log(Log::WARN, boost::format("Found only %d objects") % nobj);
For more complex messages that might include named properties, it is usually more convenient to use the streaming method:
using lsst::pex::logging::Rec; using lsst::pex::logging::Prop; Rec(mylog, Log::DEBUG) << "Completed deconvolution" << Prop("iterations", 541) << Prop("rms", 0.0032) << Rec::endr; Rec(mylog, Log::INFO) << boost::format("applying %s kernel") % kern << Prop("width", width); << Rec::endr;
The manipulator Rec::endr triggers the recording of the message to the log. Note that Rec is a shorthand typedef for the LogRec class.
lsst::pex::logging::Log::Log | ( | const int | threshold = INFO , |
const std::string & | name = "" |
||
) |
create a null log. This constructor should not normally be employed to obtain a Log; the static getDefaultLog() method should be used instead. This is provided primarily for subclasses and containers that require a no-arg constructor.
threshold | the initial importance threshold for this log |
name | the initial name for this log. An empty string (the default) denotes a root log. |
lsst::pex::logging::Log::Log | ( | const std::list< boost::shared_ptr< LogDestination > > & | destinations, |
const lsst::daf::base::PropertySet & | preamble, | ||
const std::string & | name = "" , |
||
const int | threshold = INFO , |
||
bool | defaultShowAll = false |
||
) |
create a fully configured Log. This constructor is not normally employed to obtain a Log; the static getDefaultLog() method or the createChildLog() method of should be used instead.
destinations | the list of LogDestinations to attach to this Log. |
preamble | a data properties that should be included with every recorded message to the Log. This constructor will automatically add the properties "LOG", giving the Log name and "DATE", giving the timestamp the message was recorded. |
name | the name to give this log. By default, the name will be an empty string, signifying a root log. |
threshold | the importance threshold to assign to this Log. Messages sent to this log must have a importance level equal to or greater than this value to be recorded. (Note that thresholds associated with destinations have their own thresholds that will override this one.) |
defaultShowAll | if true, log message properties will be shown by default when the messages are displayed. The default is false, indicating that their display must be turned on as needed. |
lsst::pex::logging::Log::Log | ( | const Log & | parent, |
const std::string & | childName, | ||
int | threshold = INHERIT_THRESHOLD |
||
) |
create a child of a given Log. The child log will be attached to the same streams as the provided parent Log. The full child name will be constructed from the given name, prepended by the parent's name and a ".". That is, if the parent is named "coo.coo" and the name given here is "ca-choo", then the full name will be "coo.coo.ca.choo". If the parent Log is a root Log, then the "." is not prepended.
parent | the Log that will serve as its parent. |
childName | the name of the child log, relative to the given parent. |
threshold | the threshold for the new child Log. If not provided, the value will be set to the value it had the last time it was created, or if it is being created for the first time, it is set to track the threshold of the parent. |
lsst::pex::logging::Log::Log | ( | const Log & | that | ) |
create a copy
|
virtual |
delete this Log
|
protected |
Format and call log(). Used by format(), debugf(), etc. Does not check the importance.
|
protected |
format and send a message using a variable argument list. This does not check the Log threshold; it assumes this has already been done.
void lsst::pex::logging::Log::addDestination | ( | std::ostream & | destination, |
int | threshold | ||
) |
add a destination to this log. The destination stream will included in all child Logs created from this log after a call to this function. All previously created logs, including ancestor logs, will be unaffected. The IndentedFormatter format will be used with this new destination.
destination | the stream to send messages to |
threshold | the importance threshold to use to filter messages sent to the stream. |
void lsst::pex::logging::Log::addDestination | ( | std::ostream & | destination, |
int | threshold, | ||
const boost::shared_ptr< LogFormatter > & | formatter | ||
) |
add a destination to this log. The destination stream will included in all child Logs created from this log after a call to this function. All previously created logs, including ancestor logs, will be unaffected.
destination | a pointer to the stream to send messages to. The caller is responsible for ensuring that the stream is neither closed nor its memory freed for the life of this Log. |
threshold | the importance threshold to use to filter messages sent to the stream. |
formatter | the log formatter to use. |
|
inline |
add a destination to this log. The destination stream will included in all child Logs created from this log after a call to this function. All previously created logs, including ancestor logs, will be unaffected.
Definition at line 573 of file Log.h.
void lsst::pex::logging::Log::addPreambleProperty | ( | const std::string & | name, |
const T & | val | ||
) |
|
static |
shutdown and destroy the default log
|
private |
Log* lsst::pex::logging::Log::createChildLog | ( | const std::string & | childName, |
int | threshold = INHERIT_THRESHOLD |
||
) | const |
create a child of a given Log. The child log will be attached to the same streams as the provided parent Log. The full child name will be constructed from the given name, prepended by the parent's name and a ".". That is, if the parent is named "coo.coo" and the name given here is "ca-choo", then the full name will be "coo.coo.ca.choo". If the parent Log is a root Log, then the "." is not prepended.
childName | the name of the child log, relative to the given parent. |
threshold | the threshold for the new child Log. If not provided, the value will be set to the value it had the last time it was created, or if it is being created for the first time, it is set to track the threshold of the parent. |
|
static |
create a new log and set it as the default Log
destinations | the list of LogDestinations to attach to this Log. |
preamble | a list of data properties that should be included with every recorded message to the Log. This constructor will automatically add the properties "LOG", giving the Log name and "DATE", giving the timestamp the message was recorded. |
name | the name to give this log. By default, the name will be an empty string, signifying a root log. |
threshold | the importance threshold to assign to this Log. Messages sent to this log must have a importance level equal to or greater than this value to be recorded. (Note that thresholds associated with destinations have their own thresholds that will override this one.) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void lsst::pex::logging::Log::format | ( | int | importance, |
const char * | fmt, | ||
... | |||
) |
send a simple, formatted message. Use of this function tends to perform better than log(int, boost::format) as the formatting is only done if the message will actually get recorded.
importance | how loud the message should be |
fmt | a printf-style format string |
... | the inputs to the formatting. |
|
static |
obtain the default root Log instance.
|
inline |
|
inline |
|
inline |
int lsst::pex::logging::Log::getThresholdFor | ( | const std::string & | name | ) | const |
get the importance threshold for a child Log. When a child Log of the same name is created, this is the threshold it will have.
name | the relative name of the child log |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void lsst::pex::logging::Log::log | ( | int | importance, |
const std::string & | message, | ||
const lsst::daf::base::PropertySet & | properties | ||
) |
send a message to the log
importance | how loud the message should be |
message | a simple bit of text to send in the message |
properties | a list of properties to include in the message. |
void lsst::pex::logging::Log::log | ( | int | importance, |
const std::string & | message, | ||
const std::string & | name, | ||
const T & | val | ||
) |
void lsst::pex::logging::Log::log | ( | int | importance, |
const std::string & | message, | ||
const RecordProperty< T > & | prop | ||
) |
send a message to the log
importance | how loud the message should be |
message | a simple bit of text to send in the message |
prop | a property to include in the message. |
Definition at line 717 of file Log.h.
void lsst::pex::logging::Log::log | ( | int | importance, |
const std::string & | message | ||
) |
send a simple message to the log
importance | how loud the message should be |
message | a simple bit of text to send in the message |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Mark this Log as persistent in the Citizen framework. This should be called when storing Log objects in the global scope or when they are otherwise long-lived. When this function is not called on a global instance, the Citizen framework may complain about a leaked PropertySet.
Definition at line 589 of file Log.h.
|
inline |
|
inline |
|
inline |
|
inline |
void lsst::pex::logging::Log::send | ( | const LogRecord & | record | ) |
send a fully formed LogRecord to the log destinations
|
inline |
|
staticprotected |
set the default Log. The pointer sent to this method should be a freshly minted pointer, "unowned" by anyone. That is, the caller relinguishes responsibility for deleting the log by calling this function.
void lsst::pex::logging::Log::setPreambleProperty | ( | const std::string & | name, |
const T & | val | ||
) |
|
inline |
set whether all of the properties should be displayed when rendering log records. This preference will be passed to LogFormatters via all LogRecords created by or sent via this Log. A LogFormatter may or may not choose to honor the preference, according to the purposes of its implmentation.
Note that while this attribute's default value is inherited from the root log, it is not persistently associated with the log's name like the importance threshold. If this log is destroyed and then recreated again with the same name, this attribute will revert to that of the root log.
yesno | the preference for showing all. willShowAll() will return this value. |
Definition at line 356 of file Log.h.
|
inline |
void lsst::pex::logging::Log::setThresholdFor | ( | const std::string & | name, |
int | threshold | ||
) |
set the importance threshold for a child Log. When a child Log of the same name is created, it will be assigned this threshold. Any existing Log object with name that has already explicitly set its importance threshold will not be affected; however, those that are set to inherit the threshold will be.
name | the relative name of the child log |
threshold | the importance threshold to set Logs with this name to. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
return true if this log will prefer showing all properties when rendering log records. This preference will be passed to LogFormatters via all LogRecords created by or sent via this Log. A LogFormatter may or may not choose to honor this preference when the LogRecord is rendered.
Definition at line 335 of file Log.h.
|
private |
|
protected |
|
private |
|
protected |
|
staticprotected |
|
protected |
|
static |
|
staticprotected |
|
static |
|
static |
|
static |
|
static |