libcommonc++  0.7
LogFormat Class Reference

A log message formatter. More...

#include <LogFormat.h++>

Public Member Functions

 LogFormat (String format="[%D %T] %F:%L %m")
 Construct a new LogFormat. More...
 
virtual ~LogFormat ()
 Destructor. More...
 
void setFormat (const String &format)
 Set the log message format. More...
 
void format (CharBuffer &buffer, LogLevel level, const char *file, int line, const char *message, va_list args)
 Format a log message and write it to a buffer. More...
 
void setShortDateFormat (const String &format)
 Set the short format for dates. More...
 
void setLongDateFormat (const String &format)
 Set the long format for dates. More...
 
void setShortTimeFormat (const String &format)
 Set the short format for times. More...
 
void setLongTimeFormat (const String &format)
 Set the long format for times. More...
 

Detailed Description

A log message formatter.

A format string specifies the format for log messages; it may contain format directives which allow various bits of information to be inserted into the message, and which affect the appearance of the message itself, such as font and color. The following table describes all of the available format directives.

DirectiveMeaning
%T The current time, in long format.
%t The current time, in short format.
%D The current date, in long format.
%d The current date, in short format.
%F The filename of the current source file.
%L The line number in the current source file.
%m The log message proper.
%h The ID of the calling thread.
%p The process ID.
%o The name of the host operating system.
%a The architecture of the host system.
%v The version number of the host operating system.
%u The username of the current user.
%H The hostname.
%A The application name.
%l The log level; one of the characters D, I, W, E.
%% A literal % character.
%* Begin bold text.
%_ Begin underlined text.
%# Begin inverse text.
%- Begin plain text (all other attributes off).
%0 Change text foreground color to default.
%1 Change text foreground color to black.
%2 Change text foreground color to red.
%3 Change text foreground color to green.
%4 Change text foreground color to yellow.
%5 Change text foreground color to blue.
%6 Change text foreground color to magenta.
%7 Change text foreground color to cyan.
%8 Change text foreground color to white.
%. Turn all text styles off.
%@ Turn on text autocolor.
%n A newline character.
Author
Mark Lindner

Constructor & Destructor Documentation

◆ LogFormat()

LogFormat ( String  format = "[%D %T] %F:%L %m")

Construct a new LogFormat.

Parameters
formatThe log message format.

◆ ~LogFormat()

~LogFormat ( )
virtual

Destructor.

Member Function Documentation

◆ format()

void format ( CharBuffer buffer,
LogLevel  level,
const char *  file,
int  line,
const char *  message,
va_list  args 
)

Format a log message and write it to a buffer.

This method is not meant to be used directly; it is called transparently by the Log class when one of the logging macros is used.

Parameters
bufferThe output buffer for the resulting message.
levelThe logging (severity) level for the message.
fileThe source file of the originating log statement.
lineThe source line of the originating log statement.
messageThe formatted message.
argsOptional message arguments.

◆ setFormat()

void setFormat ( const String format)

Set the log message format.

◆ setLongDateFormat()

void setLongDateFormat ( const String format)

Set the long format for dates.

See DateTimeFormat.

◆ setLongTimeFormat()

void setLongTimeFormat ( const String format)

Set the long format for times.

See DateTimeFormat.

◆ setShortDateFormat()

void setShortDateFormat ( const String format)

Set the short format for dates.

See DateTimeFormat.

◆ setShortTimeFormat()

void setShortTimeFormat ( const String format)

Set the short format for times.

See DateTimeFormat.


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