PixelLightAPI  .
Public Types | Public Member Functions | Static Public Member Functions
PLCore::Log Class Reference

Log system class. More...

#include <Log.h>

List of all members.

Public Types

enum  LogLevel {
  Quiet = 1, Always, Critical, Error,
  Warning, Info, Debug
}
 Log levels. More...

Public Member Functions

bool IsVerbose () const
 Get verbose mode (write log entries to console)
void SetVerbose (bool bVerbose, bool bVerboseLogLevelPrefix=true)
 Set verbose mode (write log entries to console)
PLCORE_API bool Open (const String &sFilename)
 Open the log file by using a filename.
PLCORE_API bool Open (const String &sFilename, LogFormatter &cLogFormatter)
 Open the log file by using a filename and an explicit log formatter instance.
PLCORE_API bool Close ()
 Close log.
String GetFilename () const
 Get log filename.
bool Output (uint8 nLogLevel, const String &sText)
 Write a string into the log.
uint8 GetLogLevel () const
 Get current log level.
void SetLogLevel (uint8 nLogLevel=Info)
 Set current log level.
uint8 GetFlushLogLevel () const
 Get log level for automatic flush.
void SetFlushLogLevel (uint8 nFlushLogLevel=Error)
 Set log level for automatic flush.
bool Flush ()
 Flush output buffer to disk.
uint32 GetBufferCount () const
 Get current amount of buffered log messages.
PLCORE_API void SetBufferCount (uint32 nBufferCount=10)
 Set how many log messages should be buffered in memory.
const Queue< String > & GetLastMessages () const
 Get a copy of the queue which holds the last log messages.
PLCORE_API String LogLevelToString (uint8 nLogLevel) const
 Get a string representation of the given log level.
LogFormatterGetLogFormatter () const
 Get log formatter.

Static Public Member Functions

static PLCORE_API LogGetInstance ()
static PLCORE_API bool HasInstance ()

Detailed Description

Log system class.

Note:
  • A configurable amount of messages is hold in a queue (the last n-messages)
  • When the queue is full a flush is done
  • A flush is also done if a specified log level is used in the output function (configurable)
  • A specified log level includes also all log levels with lower values e.g.: if the overall log level is set to info, log messages marked as warning, error or critical are written to the log, too
  • You can define as many debug log levels as you want
  • Implementation of the strategy design pattern, this class is the context

Member Enumeration Documentation

Log levels.

Remarks:
The log level 0 is reserved for messages which are generated from the log system itself.
Enumerator:
Quiet 

No log outputs

Always 

Should be used if the message should be logged always

Critical 

Should be used if an critical error occurs

Error 

Should be used if an error occurs

Warning 

Should be used for warning texts

Info 

Should be used for info texts

Debug 

Should be used for debug level texts


Member Function Documentation

static PLCORE_API Log* PLCore::Log::GetInstance ( ) [static]
static PLCORE_API bool PLCore::Log::HasInstance ( ) [static]
bool PLCore::Log::IsVerbose ( ) const [inline]

Get verbose mode (write log entries to console)

Returns:
'true' if the log is writing into the console, else 'false'
Note:
  • In addition to using an optional log formatter, the log also writes into the console in verbose mode
  • The log does not need be to be opened to write into the console
  • Android: Messages are not written into the console, instead the Android in-kernel log buffer is used (use Androids "logcat" utility to access this system log)
  • By default the log does not write into the console
void PLCore::Log::SetVerbose ( bool  bVerbose,
bool  bVerboseLogLevelPrefix = true 
) [inline]

Set verbose mode (write log entries to console)

Parameters:
[in]bVerbose'true' if the log is writing into the console, else 'false'
[in]bVerboseLogLevelPrefixShould the [LogLevel] prefix be shown?
See also:
PLCORE_API bool PLCore::Log::Open ( const String sFilename)

Open the log file by using a filename.

Parameters:
[in]sFilenameThe log's filename, the log formatter is automatically created by using the filename extension
Returns:
'true' if all went fine, else 'false' (maybe the log is already opened or the filename extension is not supported?)
Note:
PLCORE_API bool PLCore::Log::Open ( const String sFilename,
LogFormatter cLogFormatter 
)

Open the log file by using a filename and an explicit log formatter instance.

Parameters:
[in]sFilenameThe log's filename
[in]cLogFormatterLog formatter instance to be used, if this method returns successfully, the log takes over the control and is responsible for the destruction of the given instance
Returns:
'true' if all went fine, else 'false' (maybe the log is already opened?)
PLCORE_API bool PLCore::Log::Close ( )

Close log.

Returns:
'true' if all went fine, else 'false'
String PLCore::Log::GetFilename ( ) const [inline]

Get log filename.

Returns:
The log filename
bool PLCore::Log::Output ( uint8  nLogLevel,
const String sText 
) [inline]

Write a string into the log.

Parameters:
[in]nLogLevelLog level
[in]sTextText which should be written into the log
Returns:
'true' if all went fine, else 'false'
Remarks:
The text is written to the log only if the current log level is greater or equal to the specified value.
uint8 PLCore::Log::GetLogLevel ( ) const [inline]

Get current log level.

Returns:
The current log level
void PLCore::Log::SetLogLevel ( uint8  nLogLevel = Info) [inline]

Set current log level.

Parameters:
[in]nLogLevelNew current log level
uint8 PLCore::Log::GetFlushLogLevel ( ) const [inline]

Get log level for automatic flush.

Returns:
Log level for explicitly flush
void PLCore::Log::SetFlushLogLevel ( uint8  nFlushLogLevel = Error) [inline]

Set log level for automatic flush.

Parameters:
[in]nFlushLogLevelLog level for the explicitly flush
bool PLCore::Log::Flush ( ) [inline]

Flush output buffer to disk.

Returns:
'true' if all went fine, else 'false' (maybe there was nothing to flush?)
Note:
  • Only call this function if really required!
uint32 PLCore::Log::GetBufferCount ( ) const [inline]

Get current amount of buffered log messages.

Returns:
Amount of buffered log messages
PLCORE_API void PLCore::Log::SetBufferCount ( uint32  nBufferCount = 10)

Set how many log messages should be buffered in memory.

Parameters:
[in]nBufferCountNumber of messages to buffer
Note:
The nBufferCount-last log messages gets buffered
const Queue< String > & PLCore::Log::GetLastMessages ( ) const [inline]

Get a copy of the queue which holds the last log messages.

Returns:
Queue of n-last log messages
PLCORE_API String PLCore::Log::LogLevelToString ( uint8  nLogLevel) const

Get a string representation of the given log level.

Parameters:
[in]nLogLevelLog level to return the string representation from
Returns:
The string representation of the given log level

Get log formatter.

Get current log formatter.

Returns:
The current log formatter object, can be a null pointer, do NOT delete the returned instance!

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


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:14
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported