bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESLog Class Reference

Provides a mechanism for applications to log information to an external file. More...

#include <BESLog.h>

Inheritance diagram for BESLog:
Inheritance graph
Collaboration diagram for BESLog:
Collaboration graph

Public Member Functions

void dump (std::ostream &strm) const override
 dumps information about this object
 
void error (const std::string &msg) const
 Writes error msg to the log stream.
 
std::ostream * get_log_ostream () const
 
std::string get_request_id () const
 
void info (const std::string &msg) const
 Writes info msg to the log stream.
 
bool is_verbose () const
 Returns true if verbose logging is requested.
 
void request (const std::string &msg) const
 Writes request msg to the log stream.
 
void set_request_id (const std::string &id)
 Sets the current request id (cached in BESLog) to id.
 
void timing (const std::string &msg) const
 Writes timing msg to the log stream.
 
void trace_error (const std::string &msg, const std::string &file, int line) const
 Writes error msg to the log stream with FILE and LINE.
 
void trace_info (const std::string &msg, const std::string &file, int line) const
 Writes info msg to the log stream with FILE and LINE.
 
void trace_request (const std::string &msg, const std::string &file, int line) const
 Writes request msg to the log stream with FILE and LINE.
 
void trace_timing (const std::string &msg, const std::string &file, int line) const
 Writes timing msg to the log stream with FILE and LINE.
 
void trace_verbose (const std::string &msg, const std::string &file, int line) const
 Writes verbose msg to the log stream with FILE and LINE, if verbose logging is enabled.
 
pid_t update_pid ()
 Update the d_pid and the d_log_record_prolog_base values.
 
void verbose (const std::string &msg) const
 Writes verbose msg to the log stream, if verbose logging is enabled.
 
void verbose_off ()
 turns off verbose logging
 
void verbose_on ()
 turn on verbose logging
 
 ~BESLog () override
 Cleans up the logging mechanism.
 

Static Public Member Functions

static BESLogTheLog ()
 

Static Public Attributes

static const std::string mark = string("|&|")
 

Protected Member Functions

 BESLog ()
 constructor that sets up logging for the application.
 
void log_record (const std::string &record_type, const std::string &msg) const
 Writes msg to a log record with type lrt.
 
std::string log_record_begin () const
 Protected method that returns a string with the first fields of a log record.
 
void trace_log_record (const std::string &record_type, const std::string &msg, const std::string &file, int line) const
 Writes msg, file, and line to a trace log record with type lrt.
 

Detailed Description

Provides a mechanism for applications to log information to an external file.

BESLog provides a mechanism for applications to log information to an external file, such as debugging information. This file is defined in the BESKeys mechanism using the key BES.LogName.

Also provides a mechanism to define whether debugging information should be verbose or not using the BESKeys key/value pair BES.LogVerbose.

Logging can also be suspended and resumed using so named methods.

A log record is synonymous with a log line. Log fields are seperated by BESLog::mark (currently "|&|")

All log records have a "prolog" which consists of:

current_time + BESLog::mark + to_string(getpid()) + BESLog::mark + "record_type" + BESLog::mark

The BESLog API implements methods to write log records of type request, info, error, verbose, and timing. All of these logs take a single message string as their input. The users of the request logger (BESXMLInterface) and the timing logger (BESStopWatch) are responsible for injecting additional log fields for their respective use cases into the message and ultimately the log record.

It is preferred to use the logging macros REQUEST_LOG(x), INFO_LOG(x), ERROR_LOG(x), VERBOSE_LOG(x), and TIMING_LOG(x) where x is the message string.

    INFO_LOG("This is some information to be logged...");
    ERROR_LOG("OUCH! The bad things happened!");
    VERBOSE_LOG("I'm feeling chatty.");

Note:

  • The content and order of the request log fields are determined in BESXMLInterface::log_the_command()
  • The content and order of the timing log fields are determined in BESStopWatch::~BESStopWatch();
        TIMING_LOG("timing field value" + BESLog::mark + "next timing field value" + BESLog::mark + "another value");
        REQUEST_LOG("request field value" + BESLog::mark + "next request field value" + BESLog::mark + "another value");
    

BESLog provides a static method for access to a single BESLog object, TheLog.

See also
TheBESKeys

Definition at line 114 of file BESLog.h.

Constructor & Destructor Documentation

◆ BESLog()

BESLog::BESLog ( )
protected

constructor that sets up logging for the application.

Sets up logging for the application by opening up the logging file and determining verbose logging.

The file name is determined using the BESKeys mechanism. The key used is BES.LogName. The application must be able to write to this directory/file.

Verbose logging is determined also using the BESKeys mechanism. The key used is BES.LogVerbose.

By default, log using UTC. BES.LogTimeLocal=yes will switch to using local time. Times are recorded in IOS8601.

Exceptions
BESInternalErrorif BESLogName is not set or if there are problems opening or writing to the log file.
See also
BESKeys

Definition at line 77 of file BESLog.cc.

◆ ~BESLog()

BESLog::~BESLog ( )
override

Cleans up the logging mechanism.

Cleans up the logging mechanism by closing the log file.

Definition at line 172 of file BESLog.cc.

Member Function Documentation

◆ dump()

void BESLog::dump ( std::ostream & strm) const
overridevirtual

dumps information about this object

Displays the pointer value of this instance along with information about the log file

Parameters
strmC++ i/o stream to dump the information to

Implements BESObj.

Definition at line 262 of file BESLog.cc.

◆ error()

void BESLog::error ( const std::string & msg) const
inline

Writes error msg to the log stream.

Definition at line 205 of file BESLog.h.

◆ get_log_ostream()

std::ostream * BESLog::get_log_ostream ( ) const
inline

Definition at line 273 of file BESLog.h.

◆ get_request_id()

std::string BESLog::get_request_id ( ) const
inline

Definition at line 264 of file BESLog.h.

◆ info()

void BESLog::info ( const std::string & msg) const
inline

Writes info msg to the log stream.

Definition at line 198 of file BESLog.h.

◆ is_verbose()

bool BESLog::is_verbose ( ) const
inline

Returns true if verbose logging is requested.

This method returns true if verbose logging has been requested either by setting the BESKeys key/value pair BES.LogVerbose=value or by turning on verbose logging using the method verbose_on.

If BES.LogVerbose is set to Yes, YES, or yes then verbose logging is turned on. If set to anything else then verbose logging is not turned on.

Returns
true if verbose logging has been requested.
See also
verbose_on
verbose_off
BESKeys

Definition at line 184 of file BESLog.h.

◆ log_record()

void BESLog::log_record ( const std::string & lrt,
const std::string & msg ) const
protected

Writes msg to a log record with type lrt.

Parameters
lrtThe log record type
msgThe message to be logged.

Definition at line 231 of file BESLog.cc.

◆ log_record_begin()

std::string BESLog::log_record_begin ( ) const
protected

Protected method that returns a string with the first fields of a log record.

By default, the time will be expressed in ISO8601 format: "YYYY-MM-DDTHH:MM:SS zone"

However, if BES.LogUnixTime=true appears in the BES configuration then time will be expressed as a numeric unix time value.

Returns
The string: time + mark + pid + mark

Definition at line 200 of file BESLog.cc.

◆ request()

void BESLog::request ( const std::string & msg) const
inline

Writes request msg to the log stream.

Definition at line 191 of file BESLog.h.

◆ set_request_id()

void BESLog::set_request_id ( const std::string & id)

Sets the current request id (cached in BESLog) to id.

Definition at line 282 of file BESLog.cc.

◆ TheLog()

BESLog * BESLog::TheLog ( )
static

Definition at line 290 of file BESLog.cc.

◆ timing()

void BESLog::timing ( const std::string & msg) const
inline

Writes timing msg to the log stream.

Definition at line 221 of file BESLog.h.

◆ trace_error()

void BESLog::trace_error ( const std::string & msg,
const std::string & file,
int line ) const
inline

Writes error msg to the log stream with FILE and LINE.

Definition at line 242 of file BESLog.h.

◆ trace_info()

void BESLog::trace_info ( const std::string & msg,
const std::string & file,
int line ) const
inline

Writes info msg to the log stream with FILE and LINE.

Definition at line 235 of file BESLog.h.

◆ trace_log_record()

void BESLog::trace_log_record ( const std::string & lrt,
const std::string & msg,
const std::string & file,
int line ) const
protected

Writes msg, file, and line to a trace log record with type lrt.

Parameters
lrtThe log record type
msgThe message to be logged.

Definition at line 245 of file BESLog.cc.

◆ trace_request()

void BESLog::trace_request ( const std::string & msg,
const std::string & file,
int line ) const
inline

Writes request msg to the log stream with FILE and LINE.

Definition at line 228 of file BESLog.h.

◆ trace_timing()

void BESLog::trace_timing ( const std::string & msg,
const std::string & file,
int line ) const
inline

Writes timing msg to the log stream with FILE and LINE.

Definition at line 258 of file BESLog.h.

◆ trace_verbose()

void BESLog::trace_verbose ( const std::string & msg,
const std::string & file,
int line ) const
inline

Writes verbose msg to the log stream with FILE and LINE, if verbose logging is enabled.

Definition at line 249 of file BESLog.h.

◆ update_pid()

pid_t BESLog::update_pid ( )

Update the d_pid and the d_log_record_prolog_base values.

Definition at line 182 of file BESLog.cc.

◆ verbose()

void BESLog::verbose ( const std::string & msg) const
inline

Writes verbose msg to the log stream, if verbose logging is enabled.

Definition at line 212 of file BESLog.h.

◆ verbose_off()

void BESLog::verbose_off ( )
inline

turns off verbose logging

This method turns off verbose logging. If verbose logging was not already turned on then nothing changes.

Definition at line 167 of file BESLog.h.

◆ verbose_on()

void BESLog::verbose_on ( )
inline

turn on verbose logging

This method turns on verbose logging, providing applications the ability to log more detailed debugging information. If verbose is already turned on then nothing is changed.

Definition at line 160 of file BESLog.h.

Member Data Documentation

◆ mark

const string BESLog::mark = string("|&|")
static

Definition at line 152 of file BESLog.h.


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