suricata
util-debug.c File Reference
#include "suricata-common.h"
#include "threads.h"
#include "util-debug.h"
#include "util-error.h"
#include "util-enum.h"
#include "util-debug-filters.h"
#include "decode.h"
#include "detect.h"
#include "packet-queue.h"
#include "threadvars.h"
#include "output.h"
#include "tm-queuehandlers.h"
#include "tm-queues.h"
#include "tm-threads.h"
#include "util-unittest.h"
#include "util-syslog.h"
#include "rust.h"
#include "conf.h"
Include dependency graph for util-debug.c:

Go to the source code of this file.

Macros

#define MAX_SUBSTRINGS   30
 

Functions

SCError SCLogMessage (const SCLogLevel log_level, const char *file, const unsigned int line, const char *function, const SCError error_code, 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 *fmt,...)
 
void SCLogErr (int x, const char *file, const char *func, const int line, const int err, 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...
 
SCLogInitDataSCLogAllocLogInitData (void)
 Returns a pointer to a new SCLogInitData. This is a public interface intended to be used after the logging paramters 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...
 
SCLogOPIfaceCtxSCLogInitOPIfaceCtx (const char *iface_name, const char *log_format, int log_level, const char *arg)
 Creates a new output interface based on the arguments sent. The kind of output interface to be created is decided by the iface_name arg. If iface_name is "file", the arg argument will hold the filename to be used for logging purposes. If iface_name is "syslog", the arg argument holds the facility code. If iface_name is "console", arg is NULL. More...
 
void SCLogInitLogModule (SCLogInitData *sc_lid)
 Initializes the logging module. More...
 
void SCLogLoadConfig (int daemon, int verbose)
 
void SCLogDeInitLogModule (void)
 De-Initializes the logging module. More...
 
void SCLogRegisterTests ()
 

Variables

SCEnumCharMap sc_log_level_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.

Macro Definition Documentation

◆ MAX_SUBSTRINGS

#define MAX_SUBSTRINGS   30

Function Documentation

◆ SCLog()

void SCLog ( int  x,
const char *  file,
const char *  func,
const int  line,
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 paramters are read from the conf file.

Return values
sc_lidPointer to the newly created SCLogInitData \initonly

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

References SCMalloc.

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 681 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 1214 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 662 of file util-debug.c.

References SC_LOG_DEBUG, and sc_log_global_log_level.

Referenced by DetectBytejumpDoMatch(), FlowVarPrint(), HtpBodyPrint(), and SMTPProcessDataChunk().

Here is the caller graph for this function:

◆ SCLogDeInitLogModule()

void SCLogDeInitLogModule ( void  )

De-Initializes the logging module.

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

Referenced by SCLogInitLogModule().

Here is the caller graph for this function:

◆ SCLogErr()

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

◆ 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 1299 of file util-debug.c.

References SC_ERR_MUTEX, SCLogDeInitLogModule(), SCLogError, and SCMutexInit.

Referenced by InitGlobal().

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

◆ SCLogInitOPIfaceCtx()

SCLogOPIfaceCtx* SCLogInitOPIfaceCtx ( const char *  iface_name,
const char *  log_format,
int  log_level,
const char *  arg 
)

Creates a new output interface based on the arguments sent. The kind of output interface to be created is decided by the iface_name arg. If iface_name is "file", the arg argument will hold the filename to be used for logging purposes. If iface_name is "syslog", the arg argument holds the facility code. If iface_name is "console", arg is NULL.

Parameters
iface_nameInterface name. Can be "console", "file" or "syslog"
log_formatOverride for the global_log_format
log_levelOverride for the global_log_level
log_levelParameter required by a particular interface. Explained in the function description
Return values
iface_ctxPointer to the newly created output interface

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

References SC_LOG_DEBUG, SC_LOG_NOTSET, SC_LOG_OP_IFACE_CONSOLE, sc_log_op_iface_map, and SCMapEnumNameToValue().

Here is the call graph for this function:

◆ SCLogLoadConfig()

void SCLogLoadConfig ( int  daemon,
int  verbose 
)

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

References ConfGet(), ConfGetNode(), SCLogInitData_::global_log_format, SCLogInitData_::global_log_level, MAX, SC_ERR_INVALID_ARGUMENT, 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 SCError  error_code,
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 541 of file util-debug.c.

References SC_LOG_MAX_LOG_MSG_LEN, sc_log_module_initialized, and SC_OK.

Referenced by InitGlobal(), SCLog(), and SCLogErr().

Here is the caller graph for this function:

◆ SCLogRegisterTests()

void SCLogRegisterTests ( )

Definition at line 1718 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 95 of file util-debug.c.

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

◆ sc_log_level_map

SCEnumCharMap sc_log_level_map[]
Initial value:
= {
{ "Not set", SC_LOG_NOTSET},
{ "None", SC_LOG_NONE },
{ "Emergency", SC_LOG_EMERGENCY },
{ "Alert", SC_LOG_ALERT },
{ "Critical", SC_LOG_CRITICAL },
{ "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 51 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 105 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 100 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.

Referenced by SCLogInitOPIfaceCtx().

SC_LOG_DEBUG
@ SC_LOG_DEBUG
Definition: util-debug.h:62
SC_LOG_CONFIG
@ SC_LOG_CONFIG
Definition: util-debug.h:61
SC_LOG_NOTSET
@ SC_LOG_NOTSET
Definition: util-debug.h:51
SC_LOG_NOTICE
@ SC_LOG_NOTICE
Definition: util-debug.h:58
SC_LOG_INFO
@ SC_LOG_INFO
Definition: util-debug.h:59
SC_LOG_ERROR
@ SC_LOG_ERROR
Definition: util-debug.h:56
SC_LOG_OP_IFACE_FILE
@ SC_LOG_OP_IFACE_FILE
Definition: util-debug.h:71
SC_LOG_WARNING
@ SC_LOG_WARNING
Definition: util-debug.h:57
SC_LOG_ALERT
@ SC_LOG_ALERT
Definition: util-debug.h:54
SC_LOG_CRITICAL
@ SC_LOG_CRITICAL
Definition: util-debug.h:55
SC_LOG_PERF
@ SC_LOG_PERF
Definition: util-debug.h:60
SC_LOG_OP_IFACE_SYSLOG
@ SC_LOG_OP_IFACE_SYSLOG
Definition: util-debug.h:72
SC_LOG_NONE
@ SC_LOG_NONE
Definition: util-debug.h:52
SC_LOG_OP_IFACE_CONSOLE
@ SC_LOG_OP_IFACE_CONSOLE
Definition: util-debug.h:70
SC_LOG_EMERGENCY
@ SC_LOG_EMERGENCY
Definition: util-debug.h:53