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-log-gen.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...
 
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

#define MAX_SUBSTRINGS   30

Function Documentation

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

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

References SCLogConfig_::log_format, SCLogConfig_::op_filter, SCLogConfig_::op_filter_regex, SCLogConfig_::op_filter_regex_study, SCLogInitData_::op_ifaces, SCLogConfig_::op_ifaces, pcre_free_study, SCFree, SCMalloc, and SCLogConfig_::startup_message.

Referenced by SCLogDeInitLogModule(), and SCLogLoadConfig().

Here is the caller graph for this function:

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

References closelog, SCLogOPIfaceCtx_::facility, SCLogOPIfaceCtx_::file, SCLogOPIfaceCtx_::file_d, SCLogOPIfaceCtx_::fp_mutex, SCLogInitData_::global_log_format, SCLogInitData_::global_log_level, SCLogOPIfaceCtx_::iface, SCLogOPBuffer_::log_format, SCLogOPIfaceCtx_::log_format, SCLogConfig_::log_format, SCLogOPIfaceCtx_::log_level, SCLogConfig_::log_level, SCLogOPBuffer_::msg, SCLogOPIfaceCtx_::next, SCLogInitData_::op_filter, SCLogConfig_::op_filter, SCLogConfig_::op_filter_regex, SCLogConfig_::op_filter_regex_study, SCLogInitData_::op_ifaces, SCLogConfig_::op_ifaces, SCLogInitData_::op_ifaces_cnt, SCLogConfig_::op_ifaces_cnt, openlog, OutputRegisterFileRotationFlag(), SCLogOPIfaceCtx_::rotation_flag, SC_ERR_FATAL, SC_LOG_DEF_LOG_FILE, SC_LOG_DEF_LOG_FORMAT, SC_LOG_DEF_LOG_LEVEL, SC_LOG_DEF_LOG_OP_IFACE, SC_LOG_DEF_SYSLOG_FACILITY, SC_LOG_DEF_SYSLOG_FACILITY_STR, SC_LOG_ENV_LOG_FACILITY, SC_LOG_ENV_LOG_FILE, SC_LOG_ENV_LOG_FORMAT, SC_LOG_ENV_LOG_LEVEL, SC_LOG_ENV_LOG_OP_FILTER, SC_LOG_ENV_LOG_OP_IFACE, sc_log_global_log_level, SC_LOG_LEVEL_MAX, SC_LOG_MAX_LOG_FORMAT_LEN, SC_LOG_NOTSET, SC_LOG_OP_IFACE_CONSOLE, SC_LOG_OP_IFACE_FILE, SC_LOG_OP_IFACE_MAX, SC_LOG_OP_IFACE_SYSLOG, SCFree, SCLogError, SCMalloc, SCMapEnumNameToValue(), SCMapEnumValueToName(), SCMutexDestroy, SCMutexInit, SCStrdup, SCSyslogGetFacilityMap(), str, SCLogOPBuffer_::temp, TRUE, SCLogOPIfaceCtx_::type, type, and SCLogOPIfaceCtx_::use_color.

Here is the call graph for this function:

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

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

Referenced by SCLogDeInitLogModule(), and SCLogLoadConfig().

Here is the caller graph for this function:

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

References SC_LOG_DEBUG, and sc_log_global_log_level.

Referenced by AppLayerProtoDetectPrepareState(), DecodeIPV4(), DecodeIPV6(), DetectBytejumpDoMatch(), DetectFileextRegister(), DetectFilemagicRegister(), DetectFilenameRegister(), DetectMsgRegister(), DetectPortInsert(), FlowVarPrint(), HtpBodyPrint(), printUUID(), SigAddressPrepareStage1(), SMTPProcessDataChunk(), SRepLoadFileFromFD(), and StreamTcpReassembleInsertSegment().

Here is the caller graph for this function:

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.

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

References SC_ERR_FATAL, SC_ERR_MUTEX, sc_log_global_log_level, sc_log_module_cleaned, sc_log_module_initialized, SCLogDeInitLogModule(), SCLogError, SCMalloc, and SCMutexInit.

Referenced by main(), SCLogDeInitLogModule(), and SCLogLoadConfig().

Here is the call graph for this function:

Here is the caller graph for this function:

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

References SC_LOG_DEBUG, SC_LOG_NOTSET, SC_LOG_OP_IFACE_CONSOLE, SC_LOG_OP_IFACE_FILE, SC_LOG_OP_IFACE_SYSLOG, SC_LOG_OP_TYPE_REGULAR, SCMapEnumNameToValue(), and SCSyslogGetFacilityMap().

Referenced by SCLogDeInitLogModule().

Here is the call graph for this function:

Here is the caller graph for this function:

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 SCLogOPIfaceCtx_::file, SCLogOPIfaceCtx_::file_d, SCLogOPIfaceCtx_::fp_mutex, SCLogOPIfaceCtx_::iface, SCLogOPIfaceCtx_::log_format, SCLogConfig_::log_format, SCLogOPIfaceCtx_::log_level, SCLogOPIfaceCtx_::next, SCLogConfig_::op_ifaces, SCLogOPIfaceCtx_::rotation_flag, SC_ERR_FOPEN, SC_LOG_ERROR, SC_LOG_MAX_LOG_MSG_LEN, sc_log_module_initialized, SC_LOG_NOTSET, SC_LOG_OP_IFACE_CONSOLE, SC_LOG_OP_IFACE_FILE, SC_LOG_OP_IFACE_SYSLOG, SC_OK, SCLogError, SCMutexLock, SCMutexUnlock, SCLogOPIfaceCtx_::type, and SCLogOPIfaceCtx_::use_color.

Referenced by main().

Here is the caller graph for this function:

void SCLogRegisterTests ( void  )

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

References UtRegisterTest().

Here is the call graph for this function:

Variable Documentation

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 SCLogAllocLogOPBuffer(), SCLogDebugEnabled(), SCLogDeInitLogModule(), SCLogInitLogModule(), and SCLogLoadConfig().

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.

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.

Referenced by SCLogDeInitLogModule(), and SCLogInitLogModule().

int sc_log_module_initialized = 0
SCEnumCharMap sc_log_op_iface_map[]
Initial value:

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