log.h File Reference

Logging interfaces. More...

Data Structures

struct  spdk_log_flag
 

Macros

#define SPDK_DEBUGLOG_FLAG_ENABLED(name)   false
 
#define SPDK_NOTICELOG(...)    spdk_log(SPDK_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
 
#define SPDK_WARNLOG(...)    spdk_log(SPDK_LOG_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__)
 
#define SPDK_ERRLOG(...)    spdk_log(SPDK_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
 
#define SPDK_PRINTF(...)    spdk_log(SPDK_LOG_NOTICE, NULL, -1, NULL, __VA_ARGS__)
 
#define SPDK_INFOLOG(FLAG, ...)
 
#define SPDK_DEBUGLOG(...)   do { } while (0)
 
#define SPDK_LOGDUMP(...)   do { } while (0)
 
#define SPDK_LOG_REGISTER_COMPONENT(FLAG)
 

Typedefs

typedef void logfunc(int level, const char *file, const int line, const char *func, const char *format, va_list args)
 for passing user-provided log call More...
 

Enumerations

enum  spdk_log_level {
  SPDK_LOG_DISABLED = -1 , SPDK_LOG_ERROR , SPDK_LOG_WARN , SPDK_LOG_NOTICE ,
  SPDK_LOG_INFO , SPDK_LOG_DEBUG
}
 

Functions

void spdk_log_open (logfunc *logf)
 Initialize the logging module. More...
 
void spdk_log_close (void)
 Close the currently active log. More...
 
void spdk_log_enable_timestamps (bool value)
 Enable or disable timestamps.
 
void spdk_log_set_level (enum spdk_log_level level)
 Set the log level threshold to log messages. More...
 
enum spdk_log_level spdk_log_get_level (void)
 Get the current log level threshold. More...
 
int spdk_log_to_syslog_level (enum spdk_log_level level)
 Get syslog level based on SPDK current log level threshold. More...
 
void spdk_log_set_print_level (enum spdk_log_level level)
 Set the current log level threshold for printing to stderr. More...
 
enum spdk_log_level spdk_log_get_print_level (void)
 Get the current log level print threshold. More...
 
void spdk_log (enum spdk_log_level level, const char *file, const int line, const char *func, const char *format,...)
 Write messages to the log file. More...
 
void spdk_vlog (enum spdk_log_level level, const char *file, const int line, const char *func, const char *format, va_list ap)
 Same as spdk_log except that instead of being called with variable number of arguments it is called with an argument list as defined in stdarg.h. More...
 
void spdk_log_dump (FILE *fp, const char *label, const void *buf, size_t len)
 Log the contents of a raw buffer to a file. More...
 
void spdk_log_register_flag (const char *name, struct spdk_log_flag *flag)
 Register a log flag. More...
 
struct spdk_log_flagspdk_log_get_first_flag (void)
 Get the first registered log flag. More...
 
struct spdk_log_flagspdk_log_get_next_flag (struct spdk_log_flag *flag)
 Get the next registered log flag. More...
 
bool spdk_log_get_flag (const char *flag)
 Check whether the log flag exists and is enabled. More...
 
int spdk_log_set_flag (const char *flag)
 Enable the log flag. More...
 
int spdk_log_clear_flag (const char *flag)
 Clear a log flag. More...
 
void spdk_log_usage (FILE *f, const char *log_arg)
 Show all the log flags and their usage. More...
 

Detailed Description

Logging interfaces.

Macro Definition Documentation

◆ SPDK_INFOLOG

#define SPDK_INFOLOG (   FLAG,
  ... 
)
Value:
do { \
extern struct spdk_log_flag SPDK_LOG_##FLAG; \
if (SPDK_LOG_##FLAG.enabled) { \
spdk_log(SPDK_LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__); \
} \
} while (0)
Definition: log.h:182

◆ SPDK_LOG_REGISTER_COMPONENT

#define SPDK_LOG_REGISTER_COMPONENT (   FLAG)
Value:
struct spdk_log_flag SPDK_LOG_##FLAG = { \
.name = #FLAG, \
.enabled = false, \
}; \
__attribute__((constructor)) static void register_flag_##FLAG(void) \
{ \
spdk_log_register_flag(#FLAG, &SPDK_LOG_##FLAG); \
}

Typedef Documentation

◆ logfunc

typedef void logfunc(int level, const char *file, const int line, const char *func, const char *format, va_list args)

for passing user-provided log call

Parameters
levelLog level threshold.
fileName of the current source file.
lineCurrent source file line.
funcCurrent source function name.
formatFormat string to the message.
argsAdditional arguments for format string.

Enumeration Type Documentation

◆ spdk_log_level

Enumerator
SPDK_LOG_DISABLED 

All messages will be suppressed.

Function Documentation

◆ spdk_log()

void spdk_log ( enum spdk_log_level  level,
const char *  file,
const int  line,
const char *  func,
const char *  format,
  ... 
)

Write messages to the log file.

If level is set to SPDK_LOG_DISABLED, this log message won't be written.

Parameters
levelLog level threshold.
fileName of the current source file.
lineCurrent source line number.
funcCurrent source function name.
formatFormat string to the message.

◆ spdk_log_clear_flag()

int spdk_log_clear_flag ( const char *  flag)

Clear a log flag.

Parameters
flagLog flag to clear.
Returns
0 on success, -1 on failure.

◆ spdk_log_close()

void spdk_log_close ( void  )

Close the currently active log.

Messages after this call will be dropped.

◆ spdk_log_dump()

void spdk_log_dump ( FILE *  fp,
const char *  label,
const void *  buf,
size_t  len 
)

Log the contents of a raw buffer to a file.

Parameters
fpFile to hold the log.
labelLabel to print to the file.
bufBuffer that holds the log information.
lenLength of buffer to dump.

◆ spdk_log_get_first_flag()

struct spdk_log_flag* spdk_log_get_first_flag ( void  )

Get the first registered log flag.

Returns
The first registered log flag.

◆ spdk_log_get_flag()

bool spdk_log_get_flag ( const char *  flag)

Check whether the log flag exists and is enabled.

Returns
true if enabled, or false otherwise.

◆ spdk_log_get_level()

enum spdk_log_level spdk_log_get_level ( void  )

Get the current log level threshold.

Returns
the current log level threshold.

◆ spdk_log_get_next_flag()

struct spdk_log_flag* spdk_log_get_next_flag ( struct spdk_log_flag flag)

Get the next registered log flag.

Parameters
flagThe current log flag.
Returns
The next registered log flag.

◆ spdk_log_get_print_level()

enum spdk_log_level spdk_log_get_print_level ( void  )

Get the current log level print threshold.

Returns
the current log level print threshold.

◆ spdk_log_open()

void spdk_log_open ( logfunc logf)

Initialize the logging module.

Messages prior to this call will be dropped.

◆ spdk_log_register_flag()

void spdk_log_register_flag ( const char *  name,
struct spdk_log_flag flag 
)

Register a log flag.

Parameters
nameName of the log flag.
flagLog flag to be added.

◆ spdk_log_set_flag()

int spdk_log_set_flag ( const char *  flag)

Enable the log flag.

Parameters
flagLog flag to be enabled.
Returns
0 on success, -1 on failure.

◆ spdk_log_set_level()

void spdk_log_set_level ( enum spdk_log_level  level)

Set the log level threshold to log messages.

Messages with a higher level than this are ignored.

Parameters
levelLog level threshold to set to log messages.

◆ spdk_log_set_print_level()

void spdk_log_set_print_level ( enum spdk_log_level  level)

Set the current log level threshold for printing to stderr.

Messages with a level less than or equal to this level are also printed to stderr. You can use SPDK_LOG_DISABLED to completely suppress log printing.

Parameters
levelLog level threshold for printing to stderr.

◆ spdk_log_to_syslog_level()

int spdk_log_to_syslog_level ( enum spdk_log_level  level)

Get syslog level based on SPDK current log level threshold.

Parameters
levelLog level threshold
Returns
-1 for disable log print, otherwise is syslog level.

◆ spdk_log_usage()

void spdk_log_usage ( FILE *  f,
const char *  log_arg 
)

Show all the log flags and their usage.

Parameters
fFile to hold all the flags' information.
log_argCommand line option to set/enable the log flag.

◆ spdk_vlog()

void spdk_vlog ( enum spdk_log_level  level,
const char *  file,
const int  line,
const char *  func,
const char *  format,
va_list  ap 
)

Same as spdk_log except that instead of being called with variable number of arguments it is called with an argument list as defined in stdarg.h.

Parameters
levelLog level threshold.
fileName of the current source file.
lineCurrent source line number.
funcCurrent source function name.
formatFormat string to the message.
apprintf arguments