le_log.h File Reference

Go to the source code of this file.

Macros

#define LE_LOG_LEVEL_STATIC_FILTER   LE_LOG_DEBUG
 
#define LE_EMERG_ENABLED   1
 
#define LE_CRIT_ENABLED   1
 
#define LE_ERROR_ENABLED   1
 
#define LE_WARN_ENABLED   1
 
#define LE_INFO_ENABLED   1
 
#define LE_DEBUG_ENABLED   1
 
#define _LE_LOG_MSG(level, formatString, ...)
 
#define LE_DEBUG(formatString, ...)   _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)
 Debug message. More...
 
#define LE_DUMP(dataPtr, dataLength)
 
#define LE_LOG_DUMP(level, dataPtr, dataLength)   _le_LogData(level, dataPtr, dataLength, STRINGIZE(LE_FILENAME), _LE_LOG_FUNCTION_NAME, __LINE__)
 
#define LE_INFO(formatString, ...)   _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)
 Informational message. Normally expected. More...
 
#define LE_WARN(formatString, ...)   _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)
 Warning. Possibly indicates a problem. Should be addressed. More...
 
#define LE_ERROR(formatString, ...)   _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)
 
#define LE_CRIT(formatString, ...)   _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)
 
#define LE_EMERG(formatString, ...)   _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)
 Emergency. A fatal error has occurred. A process is being terminated. More...
 
#define LE_LOG_CAN_TRACE   1
 
#define LE_IS_TRACE_ENABLED(traceRef)   (le_log_IsTraceEnabled(traceRef))
 
#define LE_TRACE(traceRef, string, ...)
 
#define le_log_GetTraceRef(keywordPtr)   _le_log_GetTraceRef(LE_LOG_SESSION, (keywordPtr))
 
#define le_log_IsTraceEnabled(traceRef)   ((traceRef) == NULL ? false : *((bool *) (traceRef)))
 
#define le_log_SetFilterLevel(level)   _le_log_SetFilterLevel(LE_LOG_SESSION, (level))
 
#define le_log_GetFilterLevel()   ((LE_LOG_LEVEL_FILTER_PTR != NULL)?(*LE_LOG_LEVEL_FILTER_PTR):(LE_LOG_INFO))
 
#define le_log_EnableTrace(traceRef)   ((void)(*((bool*)(traceRef)) = true))
 
#define le_log_DisableTrace(traceRef)   ((void)(*((bool*)(traceRef)) = false))
 
#define LE_DEBUG_IF(condition, formatString, ...)
 
#define LE_INFO_IF(condition, formatString, ...)
 
#define LE_WARN_IF(condition, formatString, ...)
 
#define LE_ERROR_IF(condition, formatString, ...)
 
#define LE_CRIT_IF(condition, formatString, ...)
 
#define LE_EMERG_IF(condition, formatString, ...)
 
#define LE_FATAL(formatString, ...)
 
#define LE_FATAL_IF(condition, formatString, ...)
 
#define LE_ASSERT(condition)   LE_FATAL_IF(!(condition), "Assert Failed: '%s'", #condition)
 
#define LE_ASSERT_OK(condition)   LE_FATAL_IF((condition) != LE_OK, "Assert Failed: '%s' is not LE_OK (0)", #condition)
 
#define LE_RESULT_TXT(v)   _le_log_GetResultCodeString(v)
 
#define LE_ERRNO_TXT(v)   _le_log_GetErrnoCodeString(v)
 
#define LE_LOG_NEED_GET_ERRNO_STRING   1
 

Enumerations

enum  le_log_Level_t {
  LE_LOG_DEBUG, LE_LOG_INFO, LE_LOG_WARN, LE_LOG_ERR,
  LE_LOG_CRIT, LE_LOG_EMERG, LE_LOG_MAX
}
 

Functions

const char * _le_log_GetResultCodeString (le_result_t resultCode)
 Function that does the real work of translating result codes. See LE_RESULT_TXT. More...
 
const char * _le_log_GetErrnoCodeString (int errnoCode)
 Function that does the real work of translating result codes. See LE_RESULT_TXT. More...
 
void _le_log_ExitFatal (void)
 Function that exits in a race-free manner -- work around glibc BZ#14333.
 
LE_FULL_API void le_log_ConnectToControlDaemon (void)
 
LE_FULL_API le_log_SessionRef_t le_log_RegComponent (const char *componentNamePtr, le_log_Level_t **levelFilterPtrPtr)
 

Detailed Description

Legato Logging API include file.

Macro Definition Documentation

◆ _LE_LOG_MSG

#define _LE_LOG_MSG (   level,
  formatString,
  ... 
)
Value:
do { \
if ((level >= LE_LOG_LEVEL_STATIC_FILTER) && \
((LE_LOG_LEVEL_FILTER_PTR == NULL) || (level >= *LE_LOG_LEVEL_FILTER_PTR))) \
_le_log_Send(level, NULL, LE_LOG_SESSION, __FILE__, _LE_LOG_FUNCTION_NAME, __LINE__, \
formatString, ##__VA_ARGS__); \
} while(0)
#define LE_LOG_LEVEL_STATIC_FILTER
Definition: le_log.h:429

Internal macro to filter out messages that do not meet the current filtering level.

◆ LE_ASSERT

#define LE_ASSERT (   condition)    LE_FATAL_IF(!(condition), "Assert Failed: '%s'", #condition)

This macro does nothing if the condition is true, otherwise it logs the condition expression as a message at EMERGENCY level and then kills the calling process.

◆ LE_ASSERT_OK

#define LE_ASSERT_OK (   condition)    LE_FATAL_IF((condition) != LE_OK, "Assert Failed: '%s' is not LE_OK (0)", #condition)

This macro does nothing if the condition is LE_OK (0), otherwise it logs that the expression did not evaluate to LE_OK (0) in a message at EMERGENCY level and then kills the calling process.

◆ LE_CRIT

#define LE_CRIT (   formatString,
  ... 
)    _LE_LOG_MSG(LE_LOG_CRIT, formatString, ##__VA_ARGS__)

Critical error. Fault that almost certainly has or will result in a system failure.

◆ LE_CRIT_IF

#define LE_CRIT_IF (   condition,
  formatString,
  ... 
)
Value:
do \
{ \
if (condition) { LE_CRIT(formatString, ##__VA_ARGS__); } \
} while (0)
#define LE_CRIT(formatString,...)
Definition: le_log.h:606

LE_CRIT if condition is met.

◆ LE_DEBUG

#define LE_DEBUG (   formatString,
  ... 
)    _LE_LOG_MSG(LE_LOG_DEBUG, formatString, ##__VA_ARGS__)

Debug message.

◆ LE_DEBUG_IF

#define LE_DEBUG_IF (   condition,
  formatString,
  ... 
)
Value:
do \
{ \
if (condition) { LE_DEBUG(formatString, ##__VA_ARGS__); } \
} while (0)
#define LE_DEBUG(formatString,...)
Debug message.
Definition: le_log.h:574

LE_DEBUG if condition is met.

◆ LE_DUMP

#define LE_DUMP (   dataPtr,
  dataLength 
)
Value:
_le_LogData(LE_LOG_DEBUG, dataPtr, dataLength, STRINGIZE(LE_FILENAME), _LE_LOG_FUNCTION_NAME, \
__LINE__)
#define STRINGIZE(x)
Definition: le_basics.h:234
Debug message.
Definition: le_log.h:376

Dump a buffer of data as hexadecimal to the log at debug level.

Parameters
dataPtrBinary data to dump.
dataLengthLength og the buffer.

◆ LE_EMERG

#define LE_EMERG (   formatString,
  ... 
)    _LE_LOG_MSG(LE_LOG_EMERG, formatString, ##__VA_ARGS__)

Emergency. A fatal error has occurred. A process is being terminated.

◆ LE_EMERG_IF

#define LE_EMERG_IF (   condition,
  formatString,
  ... 
)
Value:
do \
{ \
if (condition) { LE_EMERG(formatString, ##__VA_ARGS__); } \
} while (0)
#define LE_EMERG(formatString,...)
Emergency. A fatal error has occurred. A process is being terminated.
Definition: le_log.h:608

LE_EMERG if condition is met.

◆ LE_ERRNO_TXT

#define LE_ERRNO_TXT (   v)    _le_log_GetErrnoCodeString(v)

Get a null-terminated, printable string representing an errno value.

Use this instead of strerror() or strerror_r() since those have incompatible implementations on different platforms.

Returns
Pointer to a string constant.

◆ LE_ERROR

#define LE_ERROR (   formatString,
  ... 
)    _LE_LOG_MSG(LE_LOG_ERR, formatString, ##__VA_ARGS__)

Error. Definitely indicates a fault that needs to be addressed. Possibly resulted in a system failure.

◆ LE_ERROR_IF

#define LE_ERROR_IF (   condition,
  formatString,
  ... 
)
Value:
do \
{ \
if (condition) { LE_ERROR(formatString, ##__VA_ARGS__); } \
} while (0)
#define LE_ERROR(formatString,...)
Definition: le_log.h:604

LE_ERROR if condition is met.

◆ LE_FATAL

#define LE_FATAL (   formatString,
  ... 
)
Value:
do{ \
LE_EMERG(formatString, ##__VA_ARGS__); _le_log_ExitFatal(); \
} while(0)
void _le_log_ExitFatal(void)
Function that exits in a race-free manner -- work around glibc BZ#14333.

Log fatal errors by killing the calling process after logging the message at EMERGENCY level. This macro never returns.

Accepts printf-style arguments, consisting of a format string followed by zero or more parameters to be printed (depending on the contents of the format string).

◆ LE_FATAL_IF

#define LE_FATAL_IF (   condition,
  formatString,
  ... 
)
Value:
do{ \
if (condition) { LE_FATAL(formatString, ##__VA_ARGS__); } \
}while(0)
#define LE_FATAL(formatString,...)
Definition: le_log.h:957

This macro does nothing if the condition is false, otherwise it logs the message at EMERGENCY level and then kills the calling process.

Accepts printf-style arguments, consisting of a format string followed by zero or more parameters to be printed (depending on the contents of the format string).

◆ LE_INFO

#define LE_INFO (   formatString,
  ... 
)    _LE_LOG_MSG(LE_LOG_INFO, formatString, ##__VA_ARGS__)

Informational message. Normally expected.

◆ LE_INFO_IF

#define LE_INFO_IF (   condition,
  formatString,
  ... 
)
Value:
do \
{ \
if (condition) { LE_INFO(formatString, ##__VA_ARGS__); } \
} while (0)
#define LE_INFO(formatString,...)
Informational message. Normally expected.
Definition: le_log.h:600

LE_INFO if condition is met.

◆ LE_IS_TRACE_ENABLED

#define LE_IS_TRACE_ENABLED (   traceRef)    (le_log_IsTraceEnabled(traceRef))

Queries whether or not a trace keyword is enabled.

Returns
true if the keyword is enabled. false otherwise.

◆ LE_LOG_CAN_TRACE

#define LE_LOG_CAN_TRACE   1

Mark tracing as used, so trace-related code can be compiled in.

◆ le_log_DisableTrace

#define le_log_DisableTrace (   traceRef)    ((void)(*((bool*)(traceRef)) = false))

Disables a trace.

Note
Normally, this is not necessary, since traces can be enabled at runtime using the log control tool and can be persistently configured. See Log Controls.
Parameters
traceRef[IN] Trace reference obtained from le_log_GetTraceRef()

◆ LE_LOG_DUMP

#define LE_LOG_DUMP (   level,
  dataPtr,
  dataLength 
)    _le_LogData(level, dataPtr, dataLength, STRINGIZE(LE_FILENAME), _LE_LOG_FUNCTION_NAME, __LINE__)

Dump a buffer of data as hexadecimal to the log at the specified level.

Parameters
levelLog level.
dataPtrBinary data to dump.
dataLengthLength of the buffer.

◆ le_log_EnableTrace

#define le_log_EnableTrace (   traceRef)    ((void)(*((bool*)(traceRef)) = true))

Enables a trace.

Note
Normally, this is not necessary, since traces can be enabled at runtime using the log control tool and can be persistently configured. See Log Controls.
Parameters
traceRef[IN] Trace reference obtained from le_log_GetTraceRef()

◆ le_log_GetFilterLevel

#define le_log_GetFilterLevel ( )    ((LE_LOG_LEVEL_FILTER_PTR != NULL)?(*LE_LOG_LEVEL_FILTER_PTR):(LE_LOG_INFO))

Gets the log filter level for the calling component.

◆ le_log_GetTraceRef

#define le_log_GetTraceRef (   keywordPtr)    _le_log_GetTraceRef(LE_LOG_SESSION, (keywordPtr))

Gets a reference to a trace keyword's settings.

Parameters
keywordPtr[IN] Pointer to the keyword string.
Returns
Trace reference.

◆ le_log_IsTraceEnabled

#define le_log_IsTraceEnabled (   traceRef)    ((traceRef) == NULL ? false : *((bool *) (traceRef)))

Determines if a trace is currently enabled.

Parameters
traceRef[IN] Trace reference obtained from le_log_GetTraceRef()
Returns
true if enabled, false if not.

◆ LE_LOG_LEVEL_STATIC_FILTER

#define LE_LOG_LEVEL_STATIC_FILTER   LE_LOG_DEBUG

Compile-time filtering level.

Note
Logs below this filter level will be removed at compile-time and cannot be enabled at runtime.

◆ le_log_SetFilterLevel

#define le_log_SetFilterLevel (   level)    _le_log_SetFilterLevel(LE_LOG_SESSION, (level))

Sets the log filter level for the calling component.

Note
Normally not necessary as the log filter level can be controlled at runtime using the log control tool, and can be persistently configured. See Log Controls.
Parameters
level[IN] Log filter level to apply to the current log session.

◆ LE_RESULT_TXT

#define LE_RESULT_TXT (   v)    _le_log_GetResultCodeString(v)

Get a null-terminated, printable string representing an le_result_t value.

For example, LE_RESULT_TXT(LE_NOT_PERMITTED) would return a pointer to a string containing "LE_NOT_PERMITTED".

"(unknown)" will be returned if the value given is out of range.

Returns
Pointer to a string constant.

◆ LE_TRACE

#define LE_TRACE (   traceRef,
  string,
  ... 
)
Value:
do { \
if (le_log_IsTraceEnabled(traceRef)) \
{ \
_le_log_Send((le_log_Level_t)-1, \
traceRef, \
LE_LOG_SESSION, \
STRINGIZE(LE_FILENAME), \
_LE_LOG_FUNCTION_NAME, \
__LINE__, \
string, \
##__VA_ARGS__); \
} \
} while(0)
#define STRINGIZE(x)
Definition: le_basics.h:234
le_log_Level_t
Definition: le_log.h:374
#define le_log_IsTraceEnabled(traceRef)
Definition: le_log.h:673

Logs the string if the keyword has been enabled by a runtime tool or configuration setting.

◆ LE_WARN

#define LE_WARN (   formatString,
  ... 
)    _LE_LOG_MSG(LE_LOG_WARN, formatString, ##__VA_ARGS__)

Warning. Possibly indicates a problem. Should be addressed.

◆ LE_WARN_IF

#define LE_WARN_IF (   condition,
  formatString,
  ... 
)
Value:
do \
{ \
if (condition) { LE_WARN(formatString, ##__VA_ARGS__); } \
} while (0)
#define LE_WARN(formatString,...)
Warning. Possibly indicates a problem. Should be addressed.
Definition: le_log.h:602

LE_WARN if condition is met.

Enumeration Type Documentation

◆ le_log_Level_t

Local definitions that should not be used directly.

Enumerator
LE_LOG_DEBUG 

Debug message.

LE_LOG_INFO 

Informational message. Normally expected.

LE_LOG_WARN 

Warning. Possibly indicates a problem. Should be addressed.

LE_LOG_ERR 

Error. Definitely indicates a fault that needs to be addressed. Possibly resulted in a system failure.

LE_LOG_CRIT 

Critical error. Fault that almost certainly has or will result in a system failure.

LE_LOG_EMERG 

Emergency. A fatal error has occurred. A process is being terminated.

LE_LOG_MAX 

One beyond maximum log level.

Function Documentation

◆ _le_log_GetErrnoCodeString()

const char * _le_log_GetErrnoCodeString ( int  errnoCode)

Function that does the real work of translating result codes. See LE_RESULT_TXT.

Parameters
[in]errnoCodeerrno value to be translated.

◆ _le_log_GetResultCodeString()

const char* _le_log_GetResultCodeString ( le_result_t  resultCode)

Function that does the real work of translating result codes. See LE_RESULT_TXT.

Parameters
[in]resultCodeResult code value to be translated.

◆ le_log_ConnectToControlDaemon()

LE_FULL_API void le_log_ConnectToControlDaemon ( void  )

Connects to the Log Control Daemon. This must not be done until after the Messaging system is initialized, but must be done before the main thread's Event Loop starts to ensure that all log settings are received from the Log Control Daemon and applied to sessions in the local process before any component initialization functions are run.

◆ le_log_RegComponent()

LE_FULL_API le_log_SessionRef_t le_log_RegComponent ( const char *  componentNamePtr,
le_log_Level_t **  levelFilterPtrPtr 
)

Registers a named component with the logging system.

Returns
A log session reference. This reference must be kept by the component and accessible through a local macro with the name LE_LOG_SESSION.
Parameters
[in]componentNamePtrA pointer to the component's name.
[out]levelFilterPtrPtrSet to point to the component's level filter.