suricata
util-debug.c File Reference
#include "suricata-common.h"
#include "util-debug.h"
#include "output.h"
#include "suricata.h"
#include "util-conf.h"
#include "util-enum.h"
#include "util-path.h"
#include "util-syslog.h"
#include "util-time.h"
Include dependency graph for util-debug.c:

Go to the source code of this file.

Functions

SCError SCLogMessage (const SCLogLevel log_level, const char *file, const unsigned int line, const char *function, const char *module, const char *message)
 Adds the global log_format to the outgoing buffer. More...
 
void SCLog (int x, const char *file, const char *func, const int line, const char *module, const char *fmt,...)
 
void SCLogErr (int x, const char *file, const char *func, const int line, const char *module, const char *fmt,...)
 
int SCLogDebugEnabled (void)
 Returns whether debug messages are enabled to be logged or not. More...
 
SCLogOPBufferSCLogAllocLogOPBuffer (void)
 Allocates an output buffer for an output interface. Used when we want the op_interface log_format to override the global_log_format. Currently not used. More...
 
SCLogLevel SCLogGetLogLevel (void)
 
SCLogInitDataSCLogAllocLogInitData (void)
 Returns a pointer to a new SCLogInitData. This is a public interface intended to be used after the logging parameters are read from the conf file. More...
 
void SCLogAppendOPIfaceCtx (SCLogOPIfaceCtx *iface_ctx, SCLogInitData *sc_lid)
 Appends an output_interface to the output_interface list sent in head. More...
 
void SCLogInitLogModule (SCLogInitData *sc_lid)
 Initializes the logging module. More...
 
void SCLogLoadConfig (int daemon, int verbose, uint32_t userid, uint32_t groupid)
 
void SCLogDeInitLogModule (void)
 De-Initializes the logging module. More...
 
void SCLogRegisterTests (void)
 

Variables

SCEnumCharMap sc_log_level_map []
 
SCEnumCharMap sc_log_slevel_map []
 
SCEnumCharMap sc_log_op_iface_map []
 
SCLogLevel sc_log_global_log_level
 Holds the global log level. Is the same as sc_log_config->log_level. More...
 
int sc_log_module_initialized = 0
 Used to indicate whether the logging module has been init or not. More...
 
int sc_log_module_cleaned = 0
 Used to indicate whether the logging module has been cleaned or not. More...
 

Detailed Description

Author
Anoop Saldanha anoop.nosp@m.sald.nosp@m.anha@.nosp@m.gmai.nosp@m.l.com

Debug utility functions

Definition in file util-debug.c.

Function Documentation

◆ SCLog()

void SCLog ( int  x,
const char *  file,
const char *  func,
const int  line,
const char *  module,
const char *  fmt,
  ... 
)

◆ SCLogAllocLogInitData()

SCLogInitData* SCLogAllocLogInitData ( void  )

Returns a pointer to a new SCLogInitData. This is a public interface intended to be used after the logging parameters are read from the conf file.

Return values
sc_lidPointer to the newly created SCLogInitData \initonly

Definition at line 1250 of file util-debug.c.

References SCCalloc.

Referenced by SCLogLoadConfig().

Here is the caller graph for this function:

◆ SCLogAllocLogOPBuffer()

SCLogOPBuffer* SCLogAllocLogOPBuffer ( void  )

Allocates an output buffer for an output interface. Used when we want the op_interface log_format to override the global_log_format. Currently not used.

Return values
bufferPointer to the newly created output_buffer

Definition at line 786 of file util-debug.c.

References SCMalloc.

◆ SCLogAppendOPIfaceCtx()

void SCLogAppendOPIfaceCtx ( SCLogOPIfaceCtx iface_ctx,
SCLogInitData sc_lid 
)

Appends an output_interface to the output_interface list sent in head.

Parameters
iface_ctxPointer to the output_interface that has to be added to head
headPointer to the output_interface list

Definition at line 1306 of file util-debug.c.

References head, SCLogOPIfaceCtx_::next, SCLogInitData_::op_ifaces, and SCLogInitData_::op_ifaces_cnt.

◆ SCLogDebugEnabled()

int SCLogDebugEnabled ( void  )

Returns whether debug messages are enabled to be logged or not.

Return values
1if debug messages are enabled to be logged
0if debug messages are not enabled to be logged

Definition at line 767 of file util-debug.c.

References SC_LOG_DEBUG, and sc_log_global_log_level.

Referenced by FlowVarPrint().

Here is the caller graph for this function:

◆ SCLogDeInitLogModule()

void SCLogDeInitLogModule ( void  )

De-Initializes the logging module.

Definition at line 1597 of file util-debug.c.

Referenced by GlobalsDestroy(), and SCLogInitLogModule().

Here is the caller graph for this function:

◆ SCLogErr()

void SCLogErr ( int  x,
const char *  file,
const char *  func,
const int  line,
const char *  module,
const char *  fmt,
  ... 
)

◆ SCLogGetLogLevel()

SCLogLevel SCLogGetLogLevel ( void  )

Definition at line 1070 of file util-debug.c.

References sc_log_global_log_level.

◆ SCLogInitLogModule()

void SCLogInitLogModule ( SCLogInitData sc_lid)

Initializes the logging module.

Parameters
sc_lidThe initialization data for the logging module. If sc_lid is NULL, we would stick to the default configuration for the logging subsystem. \initonly

Definition at line 1390 of file util-debug.c.

References FatalError, SCLogDeInitLogModule(), and SCMutexInit.

Referenced by InitGlobal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCLogLoadConfig()

void SCLogLoadConfig ( int  daemon,
int  verbose,
uint32_t  userid,
uint32_t  groupid 
)

Definition at line 1420 of file util-debug.c.

References ConfGet(), ConfGetNode(), SCLogInitData_::global_log_format, SCLogInitData_::global_log_level, MAX, sc_log_level_map, SC_LOG_NOTICE, SCLogAllocLogInitData(), SCLogDebug, SCLogError, and SCMapEnumNameToValue().

Referenced by ListAppLayerProtocols(), and ListKeywords().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCLogMessage()

SCError SCLogMessage ( const SCLogLevel  log_level,
const char *  file,
const unsigned int  line,
const char *  function,
const char *  module,
const char *  message 
)

Adds the global log_format to the outgoing buffer.

Parameters
log_levellog_level of the message that has to be logged
msgBuffer containing the outgoing message
fileFile_name from where the message originated
functionFunction_name from where the message originated
lineLine_no from where the messaged originated
Return values
SC_OKon success; else an error code

Definition at line 652 of file util-debug.c.

References SC_LOG_MAX_LOG_MSG_LEN, sc_log_module_initialized, SC_OK, SCTIME_FROM_TIMEVAL, and ts.

Referenced by SCLog(), and SCLogErr().

Here is the caller graph for this function:

◆ SCLogRegisterTests()

void SCLogRegisterTests ( void  )

Definition at line 1799 of file util-debug.c.

References UtRegisterTest().

Here is the call graph for this function:

Variable Documentation

◆ sc_log_global_log_level

SCLogLevel sc_log_global_log_level

Holds the global log level. Is the same as sc_log_config->log_level.

Definition at line 101 of file util-debug.c.

Referenced by SCLog(), SCLogDebugEnabled(), SCLogErr(), and SCLogGetLogLevel().

◆ sc_log_level_map

SCEnumCharMap sc_log_level_map[]
Initial value:
= {
{ "Not set", SC_LOG_NOTSET },
{ "None", SC_LOG_NONE },
{ "Error", SC_LOG_ERROR },
{ "Warning", SC_LOG_WARNING },
{ "Notice", SC_LOG_NOTICE },
{ "Info", SC_LOG_INFO },
{ "Perf", SC_LOG_PERF },
{ "Config", SC_LOG_CONFIG },
{ "Debug", SC_LOG_DEBUG },
{ NULL, -1 }
}

Definition at line 41 of file util-debug.c.

Referenced by SCLogLoadConfig().

◆ sc_log_module_cleaned

int sc_log_module_cleaned = 0

Used to indicate whether the logging module has been cleaned or not.

Definition at line 111 of file util-debug.c.

◆ sc_log_module_initialized

int sc_log_module_initialized = 0

Used to indicate whether the logging module has been init or not.

Definition at line 106 of file util-debug.c.

Referenced by SCLogAddFDFilter(), SCLogCheckFDFilterEntry(), SCLogCheckFDFilterExit(), SCLogMatchFDFilter(), SCLogMessage(), SCLogPrintFDFilters(), SCLogPrintFGFilters(), and SCLogRemoveFDFilter().

◆ sc_log_op_iface_map

SCEnumCharMap sc_log_op_iface_map[]
Initial value:
= {
{ "Console", SC_LOG_OP_IFACE_CONSOLE },
{ "File", SC_LOG_OP_IFACE_FILE },
{ "Syslog", SC_LOG_OP_IFACE_SYSLOG },
{ NULL, -1 }
}

Definition at line 68 of file util-debug.c.

◆ sc_log_slevel_map

SCEnumCharMap sc_log_slevel_map[]
Initial value:
= {
{ "Not set", SC_LOG_NOTSET },
{ "None", SC_LOG_NONE },
{ "E", SC_LOG_ERROR },
{ "W", SC_LOG_WARNING },
{ "i", SC_LOG_NOTICE },
{ "i", SC_LOG_INFO },
{ "i", SC_LOG_PERF },
{ "i", SC_LOG_CONFIG },
{ "d", SC_LOG_DEBUG },
{ NULL, -1 }
}

Definition at line 54 of file util-debug.c.

SC_LOG_DEBUG
@ SC_LOG_DEBUG
Definition: util-debug.h:57
SC_LOG_CONFIG
@ SC_LOG_CONFIG
Definition: util-debug.h:56
SC_LOG_NOTSET
@ SC_LOG_NOTSET
Definition: util-debug.h:49
SC_LOG_NOTICE
@ SC_LOG_NOTICE
Definition: util-debug.h:53
SC_LOG_INFO
@ SC_LOG_INFO
Definition: util-debug.h:54
SC_LOG_ERROR
@ SC_LOG_ERROR
Definition: util-debug.h:51
SC_LOG_OP_IFACE_FILE
@ SC_LOG_OP_IFACE_FILE
Definition: util-debug.h:66
SC_LOG_WARNING
@ SC_LOG_WARNING
Definition: util-debug.h:52
SC_LOG_PERF
@ SC_LOG_PERF
Definition: util-debug.h:55
SC_LOG_OP_IFACE_SYSLOG
@ SC_LOG_OP_IFACE_SYSLOG
Definition: util-debug.h:67
SC_LOG_NONE
@ SC_LOG_NONE
Definition: util-debug.h:50
SC_LOG_OP_IFACE_CONSOLE
@ SC_LOG_OP_IFACE_CONSOLE
Definition: util-debug.h:65