/home/elb/work/cs590n/mace/mace/lib/Log.h File Reference


Detailed Description

Details about the logging infrastructure.

All log messages have selectors and log levels. Logging can additionally be enabled or disabled at compile time or runtime.

For a log to get printed, it's level must be below (or equal to) the log level of the system. It's selector must be selected, and the logging must not be disabled. Furthermore, there is a way to disable (at compile time) all normal logs by defining some macros and/or setting a compile-time max log level.

For relevant code, look at lib/mace-macros.h and lib/LogIdSet.h.

Selectors are added by the macro ADD_SELECTORS(x); If called by ADD_FUNC_SELECTORS, it uses __PRETTY_FUNCTION__. Mace services generally use service::function::state or service::function::message::state. message is a message name or timer name, state is the guard, or "(demux)" if it's the demux method, or some other strings on generated methods. However, this format can be overridden by the log_selectors{} block. This can be done to shorten selectors for example. A prefix is added sometimes based on the macro and LogIdSet.

All logging macros use log level 0, except macecompiler(x) and macedbg(x) (or their printf variants). These take a required log level, though the macecompiler(x) versions should only be used by generated code.

Finally, there is the configuration of logging output. This handled by

Log::configure() utilizes those other ones, and references a number of configuration parameters (from the Params singleton), including params::MACE_LOG_AUTO_SELECTORS, params::MACE_LOG_LEVEL, and more. The Log::add, Log::autoAdd, and Log::autoAddAll methods allow configuration of which selectors get printed to which FILE*(s), and using what formats (timestamp, selector, thread id, etc.). By default, WARNING and ERROR are Log::autoAdd -ed to std::stderr. This can be disabled. Selectors can be printed to more than one file descriptor. Different selectors can be printed using different formats to the same file descriptor, and the same selector can be printed using different formats to different file descriptors.

A log selector string is mapped to a log_id at the beginning of the execution. If the selector is not selected before the mapping occurs, Log::NULL_ID is returned. Log::NULL_ID causes fast-pass log suppression. Otherwise the log id is an index into a data structure telling how to do the logging.

You can in theory call Log::logXXX("selector"...), which checks the selector mapping each time (though once a mapping is selected, I'm not sure it is re-evaluated). But that is highly inefficient -- instead the log_id should be used whenever possible, which the mace logging macros handle for you.

So that's just a brief introduction to Mace logging. It is supremely flexible and highly optimized, albeit a bit complex to fully understand.

That should help you get started.

Definition in file Log.h.

#include <stdio.h>
#include <list>
#include <vector>
#include <cstdarg>
#include <iostream>
#include <sstream>
#include <fstream>
#include <pthread.h>
#include "mhash_map.h"
#include "Serializable.h"
#include "LogSelector.h"
#include "BinaryLogObject.h"
#include "massert.h"

Include dependency graph for Log.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  mace

Classes

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


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