Log Class Reference

#include <Log.h>

Collaboration diagram for Log:

Collaboration graph
[legend]

List of all members.


Detailed Description

The main Mace logging subsystem class. The overview of the subsystem is defined in lib/Log.h.

With the exception of the configure and add methods, we anticipate that users generally need not call methods on the Log class. Instead, we expect users will use the mace macros in mace-macros.h.

Generally, you'll want the following setup:

 int main(int argc, char** argv) {
   params::loadparams(argc, argv);
   Log::configure();
   //optional programmed Log::add, autoAdd, or autoAddAll calls.

   //do work.
 }

In a Mace service you can use the macros directly. In other functions, you need to either call ADD_SELECTORS("string") or ADD_FUNC_SELECTORS to prepare the macros.

 int calcSum() {
   ADD_SELECTORS("calcSum");

   maceout << "This is a stream-based log, like cout" << Log::end;
   maceLog("This is a printf style log %s", ", don't you see");

   //other options include macewarn, macedbg, maceerr, maceWarn, maceDebug,
   //maceError
 }

Definition at line 165 of file Log.h.


Public Types

typedef mace::hash_map
< log_id_t, MaceOutputStream
*, mace::SoftState
StreamMap
 Maps log ids to logging output streams.

Static Public Member Functions

static log_id_t getId (const std::string &selector)
 returns the log id for the selector
static void add (const std::string &selector, FILE *fp=stdout, LogSelectorTimestamp lt=LOG_TIMESTAMP_DISABLED, LogSelectorName ln=LOG_NAME_DISABLED, LogSelectorThreadId ltid=LOG_THREADID_DISABLED, LogSelectorOutput lso=LOG_FPRINTF)
 adds a specific selector to be printed.
static void autoAddAll (FILE *fp=stdout, LogSelectorTimestamp lt=LOG_TIMESTAMP_EPOCH, LogSelectorName ln=LOG_NAME_ENABLED, LogSelectorThreadId ltid=LOG_THREADID_ENABLED, LogSelectorOutput lso=LOG_FPRINTF)
 adds selectors matching a regular expression to be printed.
static void autoAdd (const std::string &subselector, FILE *fp=stdout, LogSelectorTimestamp lt=LOG_TIMESTAMP_EPOCH, LogSelectorName ln=LOG_NAME_ENABLED, LogSelectorThreadId ltid=LOG_THREADID_ENABLED, LogSelectorOutput lso=LOG_FPRINTF)
 adds all selectors to be printed.
static void remove (const std::string &selector, FILE *fp=stdout)
 Unsafe. Do not use.
static void removeAll (const std::string &selector)
 Unsafe. Do not use.
static FILE * openLogFile (const std::string &path, const char *mode="a")
 convenience method to open a logfile
static void logToFile (const std::string &path, const std::string &selector, const char *mode="w", LogSelectorTimestamp sts=LOG_TIMESTAMP_EPOCH, LogSelectorName sn=LOG_NAME_DISABLED, LogSelectorThreadId stid=LOG_THREADID_DISABLED)
 convenience method to add a selector to a newly opened log file
static void enableLogging ()
 enable logging subsystem during runtime (default)
static void disableLogging ()
 temporarily disable logging subsystem (during runtime)
static void disableDefaultError ()
 cancels default logging of errors
static void disableDefaultWarning ()
 cancels default logging of warnings
static void perror (const std::string &s)
 like C's perror, but prints to Log::err()
static MaceOutputStream & err ()
 returns a log stream based on the selector "ERROR"
static MaceOutputStream & warn ()
 returns a log stream based on the selector "WARNING"
static MaceOutputStream & info ()
 returns a log stream based on the selector "INFO"
static MaceOutputStream & log (log_id_t id, log_level_t level=DEFAULT_LEVEL)
static void binaryLog (log_id_t id, const std::string &log_type, const std::string &serializedObj, log_level_t level=DEFAULT_LEVEL)
 Logs serializedObj of log type log_type according to selector id at level level.
static void binaryLog (log_id_t id, const mace::BinaryLogObject &object, log_level_t level=DEFAULT_LEVEL)
 Serializes object and uses it for binary log, and/or prints it to a string log.
static MaceOutputStream & log (const std::string &selector, log_level_t level=DEFAULT_LEVEL)
 Returns a log stream from a selector string and level.
static void log (log_id_t id, const std::string &message)
 logs a message for id at Log::DEFAULT_LEVEL
static void log (log_id_t id, log_level_t level, const std::string &message)
 logs a message for id and level
static void log (const std::string &selector, const std::string &message)
static void log (const std::string &selector, log_level_t level, const std::string &message)
static void log (log_id_t id, log_level_t level, const char *message)
 Lowest level log method.
static void log (const std::string &selector, const char *message)
static void log (const std::string &selector, log_level_t level, const char *message)
static void logf (log_id_t id, const char *format...) __attribute__((format(printf
 printf style log with id
static void static void logf (log_id_t id, log_level_t level, const char *format...) __attribute__((format(printf
 printf style log with id and level
static void static void static void logf (const std::string &selector, const char *format...) __attribute__((format(printf
static void static void static
void static void 
logf (const std::string &selector, log_level_t level, const char *format...) __attribute__((format(printf
static void static void static
void static void static
std::string 
toHex (const std::string &s)
 helper method to convert s to a hex string to return.
static void flush (MaceOutputStream &s)
 called when Log::end or Log::endl are output onto a log stream.
static log_level_t getLevel ()
 gets the current log level.
static void setLevel (log_level_t l=DEFAULT_LEVEL)
 sets the log level. Safe to change at runtime.
static void configure ()
 Causes the logging subsystem to configure itself according to the parameters.
static void nologf ()
 Used when compiling out logs.
static const NullOutputTypenolog ()
 Used when compiling out logs.

Static Public Attributes

static class
Log::LogFlushManipulator 
endl
 Simple objects used to flush a mace stream log.
static const log_level_t DEFAULT_LEVEL = 0
 The default level used for log methods.
static const log_level_t MAX_LEVEL = UINT_MAX
 The maximum log level to be printed.
static const log_id_t NULL_ID = 0
 The log id value which indicates the log is not selected.

Static Protected Member Functions

static void writeBinaryLog (log_id_t id, const LogSelector *sel, const std::string &log_type, const std::string &serializedObj)
 helper method to place a binary log in the file
static void writeTextLog (const LogSelector *sel, const char *text)
 helper method to place a text log in the file

Classes

class  MaceTraceStream
 This class is used for tracing output. Currently non-working, this was the beginning of a liblog style system for Mace. More...
class  NullOutputType
 Used when compiling logging out. Designed to do nothing. More...
class  ThreadSpecific
 Used internally by logging to store streams and per-thread information. More...

Member Function Documentation

log_id_t Log::getId ( const std::string &  selector  )  [static]

returns the log id for the selector

If the selector is selected for output, this method returns an id which matches the selector string. If the selector is not selected, Log::NULL_ID is returned instead.

Parameters:
selector The string identifying the log class. e.g. Class::function
Returns:
the log id, or Log::NULL_ID

Definition at line 118 of file Log.cc.

References LogSelector::getLogSelectorOutput(), LOG_BINARY, NULL_ID, and writeBinaryLog().

Referenced by Accumulator::Instance(), log(), ScopedLog::ScopedLog(), and mace::ScopedStackExecution::ScopedStackExecution().

static void Log::add ( const std::string &  selector,
FILE *  fp = stdout,
LogSelectorTimestamp  lt = LOG_TIMESTAMP_DISABLED,
LogSelectorName  ln = LOG_NAME_DISABLED,
LogSelectorThreadId  ltid = LOG_THREADID_DISABLED,
LogSelectorOutput  lso = LOG_FPRINTF 
) [static]

adds a specific selector to be printed.

All parameters have a default value except the selector itself. By default, it will execute a text-stdout add with no timestamp, log name, threadid.

Parameters:
selector The selector to be added.
fp The FILE* to print it to.
lt The format of the timestamp.
ln Whether or not to print the selector name.
ltid Whether or not (and how) to print the thread id.
lso How to print the log, text, binary, or pip annotation.

void Log::autoAddAll ( FILE *  fp = stdout,
LogSelectorTimestamp  lt = LOG_TIMESTAMP_EPOCH,
LogSelectorName  ln = LOG_NAME_ENABLED,
LogSelectorThreadId  ltid = LOG_THREADID_ENABLED,
LogSelectorOutput  lso = LOG_FPRINTF 
) [static]

adds selectors matching a regular expression to be printed.

All parameters have a default value except the selector itself. By default, it will execute a text-stdout add with timestamp, log name, and threadid.

Parameters:
fp The FILE* to print it to.
lt The format of the timestamp.
ln Whether or not to print the selector name.
ltid Whether or not (and how) to print the thread id.
lso How to print the log, text, binary, or pip annotation.

Definition at line 361 of file Log.cc.

Referenced by configure().

static void Log::autoAdd ( const std::string &  subselector,
FILE *  fp = stdout,
LogSelectorTimestamp  lt = LOG_TIMESTAMP_EPOCH,
LogSelectorName  ln = LOG_NAME_ENABLED,
LogSelectorThreadId  ltid = LOG_THREADID_ENABLED,
LogSelectorOutput  lso = LOG_FPRINTF 
) [static]

adds all selectors to be printed.

All parameters have a default value except the selector itself. By default, it will execute a text-stdout add with timestamp, log name, threadid.

Parameters:
subselector The selector regex to be added.
fp The FILE* to print it to.
lt The format of the timestamp.
ln Whether or not to print the selector name.
ltid Whether or not (and how) to print the thread id.
lso How to print the log, text, binary, or pip annotation.

Referenced by configure().

static void Log::remove ( const std::string &  selector,
FILE *  fp = stdout 
) [static]

Unsafe. Do not use.

Deprecated:
unsafe

static void Log::removeAll ( const std::string &  selector  )  [static]

Unsafe. Do not use.

Deprecated:
unsafe

Log::MaceOutputStream & Log::log ( log_id_t  id,
log_level_t  level = DEFAULT_LEVEL 
) [static]

Log::MaceOutputStream & Log::log ( const std::string &  selector,
log_level_t  level = DEFAULT_LEVEL 
) [static]

Returns a log stream from a selector string and level.

Warning:
Very inefficient! Use Log::getId() to get a log_id_t, then call Log::log(log_id_t, log_level_t) instead.

Definition at line 161 of file Log.cc.

References getId(), and log().

static void Log::log ( const std::string &  selector,
const std::string &  message 
) [inline, static]

Warning:
inefficient. Use the log_id_t version instead.

Definition at line 458 of file Log.h.

References DEFAULT_LEVEL, and log().

static void Log::log ( const std::string &  selector,
log_level_t  level,
const std::string &  message 
) [static]

Warning:
inefficient. Use the log_id_t version instead.

void Log::log ( log_id_t  id,
log_level_t  level,
const char *  message 
) [static]

Lowest level log method.

Prints message according to the id and level. All other log and logf methods filter to this one.

Definition at line 173 of file Log.cc.

References ABORT, LogSelector::getLogSelectorOutput(), LOG_BINARY, LOG_FPRINTF, LOG_PIP, NULL_ID, writeBinaryLog(), and writeTextLog().

static void Log::log ( const std::string &  selector,
const char *  message 
) [inline, static]

Warning:
inefficient. Use the log_id_t version instead.

Definition at line 472 of file Log.h.

References DEFAULT_LEVEL, and log().

static void Log::log ( const std::string &  selector,
log_level_t  level,
const char *  message 
) [static]

Warning:
inefficient. Use the log_id_t version instead.

static void static void static void Log::logf ( const std::string &  selector,
const char *  format... 
) [static]

Warning:
inefficient. Use the log_id_t version instead.

static void static void static void static void Log::logf ( const std::string &  selector,
log_level_t  level,
const char *  format... 
) [static]

Warning:
inefficient. Use the log_id_t version instead.

void Log::writeBinaryLog ( log_id_t  id,
const LogSelector sel,
const std::string &  log_type,
const std::string &  serializedObj 
) [static, protected]

helper method to place a binary log in the file

Precondition:
$ id != NULL\_ID \or level > logLevel $

$ sel->getLogSelectorOutput() == LOG\_BINARY $

Definition at line 311 of file Log.cc.

References ASSERT, LogSelector::getFile(), LogSelector::getSerializedSelectorHeader(), and mace::serialize().

Referenced by binaryLog(), getId(), and log().

void Log::writeTextLog ( const LogSelector sel,
const char *  text 
) [static, protected]

helper method to place a text log in the file

Precondition:
$ id != NULL\_ID \or level > logLevel $

$ sel->getLogSelectorOutput() == LOG\_FPRINTF \or sel->getLogSelectorOutput() == LOG\_PIP $

Definition at line 334 of file Log.cc.

References ANNOTATE_NOTICE(), ASSERT, LogSelector::getFile(), LogSelector::getLogSelectorOutput(), LogSelector::getSelectorHeader(), LOG_FPRINTF, and LOG_PIP.

Referenced by binaryLog(), and log().


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

Generated on Sat Oct 4 21:30:29 2008 for Mace Library by  doxygen 1.5.5