logog
logger optimized for games
macro.hpp File Reference

Go to the source code of this file.

Namespaces

 logog
 [Thread]
 

Macros

#define LOGOG_GROUP   NULL
 
#define LOGOG_CATEGORY   NULL
 
#define TOKENPASTE2(x, y)   x ## y
 
#define TOKENPASTE(x, y)   TOKENPASTE2(x, y)
 
#define LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE_NO_VA(level, group, cat, msg)
 
#define LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE(level, group, cat, formatstring, ...)
 
#define LOGOG_LEVEL_MESSAGE(level, formatstring, ...)   LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE( level, LOGOG_GROUP, LOGOG_CATEGORY, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_MESSAGE(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_DEBUG(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_DEBUG, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_INFO(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_INFO, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_WARN3(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN3, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_WARN2(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN2, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_WARN1(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN1, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_WARN(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_ERROR(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_ERROR, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_CRITICAL(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_CRITICAL, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_ALERT(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_ALERT, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_EMERGENCY(formatstring, ...)   LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_EMERGENCY, formatstring, ##__VA_ARGS__ )
 
#define LOGOG_SET_LEVEL(level)   ::logog::SetDefaultLevel( level );
 
#define DBUG(...)   LOGOG_DEBUG( __VA_ARGS__ )
 [Shorthand] More...
 
#define INFO(...)   LOGOG_INFO( __VA_ARGS__ )
 
#define WARN3(...)   LOGOG_WARN3( __VA_ARGS__ )
 
#define WARN2(...)   LOGOG_WARN2( __VA_ARGS__ )
 
#define WARN1(...)   LOGOG_WARN1( __VA_ARGS__ )
 
#define WARN(...)   LOGOG_WARN( __VA_ARGS__ )
 
#define ERR(...)   LOGOG_ERROR( __VA_ARGS__ )
 
#define ALERT(...)   LOGOG_ALERT( __VA_ARGS__ )
 
#define CRITICAL(...)   LOGOG_CRITICAL( __VA_ARGS__ )
 
#define EMERGENCY(...)   LOGOG_EMERGENCY( __VA_ARGS__ )
 
#define LOGOG_INITIALIZE(...)   logog::Initialize( __VA_ARGS__ )
 [Shorthand] More...
 
#define LOGOG_SHUTDOWN()   logog::Shutdown()
 

Detailed Description

Macros for instantiation of a message.

Macro Definition Documentation

#define ALERT (   ...)    LOGOG_ALERT( __VA_ARGS__ )
See also
LOGOG_ALERT
#define CRITICAL (   ...)    LOGOG_CRITICAL( __VA_ARGS__ )
See also
LOGOG_CRITICAL
#define DBUG (   ...)    LOGOG_DEBUG( __VA_ARGS__ )

[Shorthand]

Define this compilation flag if your compilation environment conflicts with any of the shorthand logging macros in macro.hpp.

See also
LOGOG_DEBUG
#define EMERGENCY (   ...)    LOGOG_EMERGENCY( __VA_ARGS__ )
See also
LOGOG_EMERGENCY
#define ERR (   ...)    LOGOG_ERROR( __VA_ARGS__ )
See also
LOGOG_ERROR
#define INFO (   ...)    LOGOG_INFO( __VA_ARGS__ )
See also
LOGOG_INFO
#define LOGOG_ALERT (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_ALERT, formatstring, ##__VA_ARGS__ )

Logs a message at the ALERT reporting level.

#define LOGOG_CATEGORY   NULL

This is the current category for created messages. Set this to NULL if you want messages to not be part of any specific group.

#define LOGOG_CRITICAL (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_CRITICAL, formatstring, ##__VA_ARGS__ )

Logs a message at the CRITICAL reporting level.

#define LOGOG_DEBUG (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_DEBUG, formatstring, ##__VA_ARGS__ )

Logs a message at the DEBUG reporting level.

#define LOGOG_EMERGENCY (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_EMERGENCY, formatstring, ##__VA_ARGS__ )

Logs a message at the EMERGENCY reporting level.

#define LOGOG_ERROR (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_ERROR, formatstring, ##__VA_ARGS__ )

Logs a message at the ERROR reporting level.

#define LOGOG_GROUP   NULL

This is the current group for created messages. Set this to NULL if you want messages to not be part of any specific group.

#define LOGOG_INFO (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_INFO, formatstring, ##__VA_ARGS__ )

Logs a message at the INFO reporting level.

#define LOGOG_INITIALIZE (   ...)    logog::Initialize( __VA_ARGS__ )

[Shorthand]

Call this function to initialize logog and prepare for logging.

See also
logog::Initialize()
#define LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE (   level,
  group,
  cat,
  formatstring,
  ... 
)
Value:
LOGOG_MICROSOFT_PRAGMA_IN_MACRO(warning(disable : 4127 )) \
do \
{ \
___pMCM->MutexLock(); \
static bool TOKENPASTE(_logog_static_bool_,__LINE__) = false; \
static logog::Message * TOKENPASTE(_logog_,__LINE__); \
if ( TOKENPASTE(_logog_static_bool_,__LINE__) == false ) \
{ \
TOKENPASTE(_logog_,__LINE__) = \
new logog::Message( level, \
LOGOG_CONST_STRING( __FILE__ ), \
__LINE__ , \
LOGOG_CONST_STRING( group ), \
0.0f, \
& (TOKENPASTE(_logog_static_bool_,__LINE__)) ); \
} \
___pMCM->MutexUnlock(); \
/* A race condition could theoretically occur here if you are shutting down at the same instant as sending log messages. */ \
TOKENPASTE(_logog_,__LINE__)->m_Transmitting.MutexLock(); \
TOKENPASTE(_logog_,__LINE__)->Format( formatstring, ##__VA_ARGS__ ); \
TOKENPASTE(_logog_,__LINE__)->Transmit(); \
TOKENPASTE(_logog_,__LINE__)->m_Transmitting.MutexUnlock(); \
} while (false) \
#define LOGOG_CONST_STRING(x)
Definition: string.hpp:27
[Mutex]
Definition: mutex.hpp:48
Definition: message.hpp:14
Mutex & GetMessageCreationMutex()
#define LOGOG_MICROSOFT_PRAGMA_IN_MACRO(x)
Definition: platform.hpp:142
#define TOKENPASTE(x, y)
Definition: macro.hpp:35

This macro is used when a message is instantiated with varargs provided by the user. It locks a global mutex, creates the message, locks it, formats the message string inside the message, transmits it, and releases all locks. When logog is shut down, it may be started back up again later. Therefore, logog needs a way to flag all static Message pointers that they need to be recreated. We manually simulate a static Message pointer by implementing it via a static bool. The bool is turned on the first time this code is run. NOTE! A subtle race condition exists in the following code, that will ONLY occur if logog is shut down at the same moment that a log message is processed from another thread than the one calling the shutdown. The Message object could theoretically be destroyed from another thread just before it's locked in a thread that calls the Format() and Transmit() calls on it. I'm not sure if this is really a bug – technically, this race condition will occur only if you are calling log messages right on top of the SHUTDOWN call from the main thread.

#define LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE_NO_VA (   level,
  group,
  cat,
  msg 
)
Value:
{ \
Mutex *___pMCM = &GetMessageCreationMutex(); \
___pMCM->MutexLock(); \
static logog::Message *TOKENPASTE(_logog_,__LINE__) = new logog::Message( level, \
LOGOG_CONST_STRING( __FILE__ ), \
__LINE__ , \
LOGOG_CONST_STRING( group ), \
msg; \
___pMCM->MutexUnlock(); \
TOKENPASTE(_logog_,__LINE__)->m_Transmitting.MutexLock(); \
TOKENPASTE(_logog_,__LINE__)->Transmit(); \
TOKENPASTE(_logog_,__LINE__)->m_Transmitting.MutexUnlock(); \
}
#define LOGOG_CONST_STRING(x)
Definition: string.hpp:27
Definition: message.hpp:14
Mutex & GetMessageCreationMutex()
#define TOKENPASTE(x, y)
Definition: macro.hpp:35

This macro is used when a message is instantiated without any varargs provided by the user. It locks a global mutex, creates the message, locks it, transmits it, and releases all locks.

#define LOGOG_LEVEL_MESSAGE (   level,
  formatstring,
  ... 
)    LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE( level, LOGOG_GROUP, LOGOG_CATEGORY, formatstring, ##__VA_ARGS__ )

Calls LOGOG_LEVEL_GROUP_CATEGORY_MESSAGE with the current LOGOG_GROUP and LOGOG_CATEGORY setting.

#define LOGOG_MESSAGE (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL, formatstring, ##__VA_ARGS__ )

Calls LOGOG_LEVEL_MESSAGE with the current LOGOG_LEVEL setting.

#define LOGOG_SET_LEVEL (   level)    ::logog::SetDefaultLevel( level );
#define LOGOG_SHUTDOWN ( )    logog::Shutdown()

Call this function to shut down logog and release all memory allocated.

See also
logog::Shutdown()
#define LOGOG_WARN (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN, formatstring, ##__VA_ARGS__ )

Logs a message at the WARN reporting level.

#define LOGOG_WARN1 (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN1, formatstring, ##__VA_ARGS__ )

Logs a message at the WARN1 reporting level.

#define LOGOG_WARN2 (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN2, formatstring, ##__VA_ARGS__ )

Logs a message at the WARN2 reporting level.

#define LOGOG_WARN3 (   formatstring,
  ... 
)    LOGOG_LEVEL_MESSAGE( LOGOG_LEVEL_WARN3, formatstring, ##__VA_ARGS__ )

Logs a message at the WARN3 reporting level.

#define TOKENPASTE (   x,
 
)    TOKENPASTE2(x, y)
#define TOKENPASTE2 (   x,
 
)    x ## y

When you have a macro replacement, the preprocessor will only expand the macros recursively if neither the stringizing operator # nor the token-pasting operator ## are applied to it. So, you have to use some extra layers of indirection, you can use the token-pasting operator with a recursively expanded argument.

#define WARN (   ...)    LOGOG_WARN( __VA_ARGS__ )
See also
LOGOG_WARN
#define WARN1 (   ...)    LOGOG_WARN1( __VA_ARGS__ )
See also
LOGOG_WARN1
#define WARN2 (   ...)    LOGOG_WARN2( __VA_ARGS__ )
See also
LOGOG_WARN2
#define WARN3 (   ...)    LOGOG_WARN3( __VA_ARGS__ )
See also
LOGOG_WARN3