Wt::WLogger Class Reference

A simple logging class. More...

#include <Wt/WLogger>

List of all members.

Public Member Functions

 WLogger ()
 Create a new logger.
 ~WLogger ()
 Destructor.
void setStream (std::ostream &o)
 Set the output stream.
void setFile (const std::string &path)
 Set the output file.
void addField (const std::string &name, bool isString)
 Add a field.
const std::vector< Field > & fields () const
 Returns the field list.
WLogEntry entry () const
 Start a new log entry.

Static Public Attributes

static const Sep sep = WLogger::Sep()
 Field separator constant.
static const TimeStamp timestamp = WLogger::TimeStamp()
 Timestamp field constant.

Classes

class  Field
 Class that holds the configuration for a single field. More...
struct  Sep
 Class that indicates a field separator. More...
struct  TimeStamp
 Class that indicates a time stamp. More...


Detailed Description

A simple logging class.

This class logs events to a stream in a flexible way. It allows to create log files using the commonly used Common Log Format or Combined Log Format, but provides a general way for logging entries that consists of a fixed number of fields.

It is used by Wt to create the application log (WApplication::log()), and built-in httpd access log.

To use this class for custom logging, you should instantiate a logger, add one or more field definitions using addField(), and set an output stream using setStream() or setFile(). To stream data to the logger, use entry() to start formatting a new entry.

Usage example:

 // Setup the logger
 Wt::WLogger logger;
 logger.addField("datetime", false);
 logger.addField("session", false);
 logger.addField("type", false);
 logger.addField("message", true);

 logger.setFile("/tmp/mylog.txt");

 // Add an entry
 Wt::WLogEntry entry = logger.entry();
 entry << Wt::WLogger::timestamp << Wt::WLogger::sep
       << '[' << wApp->sessionId() << ']' << Wt::WLogger::sep
       << '[' << "notice" << ']' << Wt::WLogger::sep
       << "Succesfully started.";

See also:
WApplication::log()

Member Function Documentation

void Wt::WLogger::setStream ( std::ostream &  o  ) 

Set the output stream.

See also:
setFile()

void Wt::WLogger::setFile ( const std::string &  path  ) 

Set the output file.

Opens a file output stream for path.

See also:
setStream()

void Wt::WLogger::addField ( const std::string &  name,
bool  isString 
)

Add a field.

Add a field to the logger. When isString is true, values will be quoted.

WLogEntry Wt::WLogger::entry (  )  const

Start a new log entry.

Returns a new entry. The entry is logged in the destructor of the entry (i.e. when the entry goes out of scope).


Member Data Documentation

Field separator constant.

See also:
WLogEntry::operator<<(const WLogger::Sep&)

Timestamp field constant.

See also:
WLogEntry::operator<<(const WLogger::TimeStamp&)


Generated on Tue Sep 1 17:51:16 2009 for Wt by doxygen 1.5.6