My Project
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ParaEngine::CLogger Class Reference

a logger can only write to a given file. More...

#include <Log.h>

Inheritance diagram for ParaEngine::CLogger:
ParaEngine::CServiceLogger

Public Member Functions

void AddLogStr (const char *pStr)
 [thread safe]
 
void AddLogStr (const wchar_t *pStr)
 
void AddLogStr_st (const char *pStr)
 single threaded version
 
void AddLogStr_st (const wchar_t *pStr)
 
void SetLogFile (const std::string &sFile)
 change the log file. More...
 
const std::string & GetLogFile ()
 
void WriteFormated (const char *,...)
 output to log file a formatted string [thread safe]
 
void WriteFormatedVarList (const char *, va_list args)
 
void WriteFormated (const wchar_t *,...)
 
void WriteFormated_WithTime (const char *,...)
 
void WriteFormated_st (const char *,...)
 single threaded version
 
void WriteFormated_st (const wchar_t *,...)
 
int Write (const char *buf, int nLength)
 write byte array [thread safe] More...
 
int Write_st (const char *buf, int nLength)
 single threaded version
 
int GetPos ()
 get the current log file position. More...
 
const char * GetLog (int fromPos, int nCount)
 get log text between two Log positions. More...
 
void CloseLog ()
 close the log file handle
 
FILE * GetLogFileHandle ()
 get the log file handle, and seek to end of file for immediate writing. More...
 
void WriteDebugStr (const char *zFormat, const char *str, const char *sFile, int nLine)
 output a string to log file with a given file name and line number in a given format,when compiled in debug mode e.g. More...
 
const std::string & GetName ()
 Get the logger name.
 
void SetAppendMode (bool bAppendToExistingFile)
 by default, append mode is enabled in server mode, and disabled in client build. More...
 
void SetForceFlush (bool bForceFlush)
 if true we will flush the new log to file immediately. More...
 
int GetLevel ()
 Returns the assigned Level. More...
 
void SetLevel (const int level1)
 set level of this logger. More...
 
bool IsEnabledFor (int level)
 Check whether this logger is enabled for a given Level passed as parameter. More...
 
void log (const int level, const std::string &message, const ParaEngine::LogDetail::LocationInfo &location)
 This is the most generic printing method. More...
 
void log (const int level, const char *message, const ParaEngine::LogDetail::LocationInfo &location)
 
void log (const int level, const std::string &message)
 This is the most generic printing method. More...
 
void log (const int level, const char *message)
 
void ForcedLog (const int level, const std::string &message, const ParaEngine::LogDetail::LocationInfo &location)
 This method creates a new logging event and logs the event without further checks. More...
 
void ForcedLog (const int level, const char *message, const ParaEngine::LogDetail::LocationInfo &location)
 
void ForcedLog (const int level, const std::string &message)
 This method creates a new logging event and logs the event without further checks. More...
 
void ForcedLog (const int level, const char *message)
 

Static Public Member Functions

static CLoggerGetSingleton ()
 get the default application logger. More...
 

Protected Attributes

std::string m_log_file_name
 
FILE * m_file_handle
 
char m_buffer [MAX_DEBUG_STRING_LENGTH *2+2]
 
mutex m_mutex
 
bool m_is_first_time_open
 
bool m_bForceFlush
 if true we will flush the new log to file immediately. More...
 
std::string m_name
 The name of this logger. More...
 
int m_level
 The assigned level of this logger. More...
 

Detailed Description

a logger can only write to a given file.

Please use LogService to create different loggers. char and wchar_t are supported. Both multi-threaded and single-threaded logging functions are supported. Internally we use a mutex to sync write. Messages are written immediately to file; it uses the system IO cache.

Member Function Documentation

§ ForcedLog() [1/2]

void ParaEngine::CLogger::ForcedLog ( const int  level,
const std::string &  message,
const ParaEngine::LogDetail::LocationInfo location 
)

This method creates a new logging event and logs the event without further checks.

Parameters
levelthe level to log.
messagemessage.
locationlocation of source of logging request.

§ ForcedLog() [2/2]

void ParaEngine::CLogger::ForcedLog ( const int  level,
const std::string &  message 
)

This method creates a new logging event and logs the event without further checks.

Parameters
levelthe level to log.
messagemessage.

§ GetLevel()

int ParaEngine::CLogger::GetLevel ( )

Returns the assigned Level.

Returns
Level - the assigned Level

§ GetLog()

const char * ParaEngine::CLogger::GetLog ( int  fromPos,
int  nCount 
)

get log text between two Log positions.

Parameters
fromPosposition in bytes. if nil, it defaults to 0
nCountcount in bytes. if nil, it defaults to end of log file.
Returns
string returned.

§ GetLogFileHandle()

FILE * ParaEngine::CLogger::GetLogFileHandle ( )

get the log file handle, and seek to end of file for immediate writing.

§ GetPos()

int ParaEngine::CLogger::GetPos ( )

get the current log file position.

it is equivalent to the log file size in bytes. one can later get log text between two Log positions.

§ GetSingleton()

CLogger & ParaEngine::CLogger::GetSingleton ( )
static

get the default application logger.

§ IsEnabledFor()

bool ParaEngine::CLogger::IsEnabledFor ( int  level)

Check whether this logger is enabled for a given Level passed as parameter.

Returns
bool True if this logger is enabled for level. It just checks (level>=this->m_level)

§ log() [1/2]

void ParaEngine::CLogger::log ( const int  level,
const std::string &  message,
const ParaEngine::LogDetail::LocationInfo location 
)

This is the most generic printing method.

It is intended to be invoked by wrapper classes.

Parameters
levelThe level of the logging request.
messageThe message of the logging request.
locationThe source file of the logging request, may be null.

§ log() [2/2]

void ParaEngine::CLogger::log ( const int  level,
const std::string &  message 
)

This is the most generic printing method.

It is intended to be invoked by wrapper classes.

Parameters
levelThe level of the logging request.
messageThe message of the logging request.

§ SetAppendMode()

void ParaEngine::CLogger::SetAppendMode ( bool  bAppendToExistingFile)

by default, append mode is enabled in server mode, and disabled in client build.

§ SetForceFlush()

void ParaEngine::CLogger::SetForceFlush ( bool  bForceFlush)

if true we will flush the new log to file immediately.

otherwise, flush operation is determined by the system. default to true for client log and false for service log.

§ SetLevel()

void ParaEngine::CLogger::SetLevel ( const int  level1)

set level of this logger.

§ SetLogFile()

void ParaEngine::CLogger::SetLogFile ( const std::string &  sFile)

change the log file.

§ Write()

int ParaEngine::CLogger::Write ( const char *  buf,
int  nLength 
)

write byte array [thread safe]

Parameters
bufbuffer pointer
nLengthbuffer length in bytes.
Returns
: bytes return. or -1 if failed.

§ WriteDebugStr()

void ParaEngine::CLogger::WriteDebugStr ( const char *  zFormat,
const char *  str,
const char *  sFile,
int  nLine 
)

output a string to log file with a given file name and line number in a given format,when compiled in debug mode e.g.

WriteDebugStr("%s failed in %s() [%d]\n","ErrorXXX", FILE,LINE);

Parameters
strshould be a formated string.

Member Data Documentation

§ m_bForceFlush

bool ParaEngine::CLogger::m_bForceFlush
protected

if true we will flush the new log to file immediately.

otherwise, flush operation is determined by the system. default to true for client log and false for service log.

§ m_level

int ParaEngine::CLogger::m_level
protected

The assigned level of this logger.

Default to 0, the higher, the more important. The level variable need not be assigned a value in which case it is inherited from parent.

§ m_name

std::string ParaEngine::CLogger::m_name
protected

The name of this logger.


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