suricata
|
#include "suricata-common.h"
#include "threads.h"
#include "util-enum.h"
#include "util-error.h"
#include "util-debug-filters.h"
#include "util-atomic.h"
Go to the source code of this file.
Data Structures | |
struct | SCLogOPBuffer_ |
Structure to be used when log_level override support would be provided by the logging module. More... | |
struct | SCLogOPIfaceCtx_ |
The output interface context for the logging module. More... | |
struct | SCLogInitData_ |
Structure containing init data, that would be passed to SCInitDebugModule() More... | |
struct | SCLogConfig_ |
Holds the config state used by the logging api. More... | |
Macros | |
#define | SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL" |
ENV vars that can be used to set the properties for the logging module. More... | |
#define | SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE" |
#define | SC_LOG_ENV_LOG_FILE "SC_LOG_FILE" |
#define | SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY" |
#define | SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT" |
#define | SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER" |
#define | SC_LOG_DEF_LOG_FORMAT_REL "%t - <%d> - " |
#define | SC_LOG_DEF_LOG_FORMAT_DEV "[%i] %t - (%f:%l) <%d> (%n) -- " |
#define | SC_LOG_MAX_LOG_MSG_LEN 2048 |
#define | SC_LOG_MAX_LOG_FORMAT_LEN 128 |
#define | SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO |
#define | SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE |
#define | SC_LOG_DEF_LOG_FILE "suricata.log" |
#define | SC_LOG_DEF_SYSLOG_FACILITY_STR "local0" |
#define | SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0 |
#define | SC_LOG_FMT_TIME 't' /* Timestamp in standard format */ |
#define | SC_LOG_FMT_PID 'p' /* PID */ |
#define | SC_LOG_FMT_TID 'i' /* Thread ID */ |
#define | SC_LOG_FMT_TM 'm' /* Thread module name */ |
#define | SC_LOG_FMT_LOG_LEVEL 'd' /* Log level */ |
#define | SC_LOG_FMT_FILE_NAME 'f' /* File name */ |
#define | SC_LOG_FMT_LINE 'l' /* Line number */ |
#define | SC_LOG_FMT_FUNCTION 'n' /* Function */ |
#define | SC_LOG_FMT_PREFIX '%' |
#define | SCLogInfo(...) |
Macro used to log INFORMATIONAL messages. More... | |
#define | SCLogInfoRaw(file, func, line, ...) |
#define | SCLogConfig(...) |
#define | SCLogPerf(...) |
#define | SCLogNotice(...) |
Macro used to log NOTICE messages. More... | |
#define | SCLogNoticeRaw(file, func, line, ...) |
#define | SCLogWarning(err_code, ...) |
Macro used to log WARNING messages. More... | |
#define | SCLogWarningRaw(err_code, file, func, line, ...) SCLogErr(SC_LOG_WARNING, (file), (func), (line), err_code, __VA_ARGS__) |
#define | SCLogError(err_code, ...) |
Macro used to log ERROR messages. More... | |
#define | SCLogErrorRaw(err_code, file, func, line, ...) |
#define | SCLogCritical(err_code, ...) |
Macro used to log CRITICAL messages. More... | |
#define | SCLogAlert(err_code, ...) |
Macro used to log ALERT messages. More... | |
#define | SCLogEmerg(err_code, ...) |
Macro used to log EMERGENCY messages. More... | |
#define | SCLogDebug(...) do { } while (0) |
#define | SCEnter(...) |
#define | SCReturn return |
#define | SCReturnInt(x) return x |
#define | SCReturnUInt(x) return x |
#define | SCReturnDbl(x) return x |
#define | SCReturnChar(x) return x |
#define | SCReturnCharPtr(x) return x |
#define | SCReturnCT(x, type) return x |
#define | SCReturnPtr(x, type) return x |
#define | SCReturnBool(x) return x |
#define | SCReturnStruct(x) return x |
#define | FatalError(x, ...) |
#define | FatalErrorOnInit(x, ...) |
Fatal error IF we're starting up, and configured to consider errors to be fatal errors. More... | |
Typedefs | |
typedef struct SCLogOPBuffer_ | SCLogOPBuffer |
Structure to be used when log_level override support would be provided by the logging module. More... | |
typedef struct SCLogOPIfaceCtx_ | SCLogOPIfaceCtx |
The output interface context for the logging module. More... | |
typedef struct SCLogInitData_ | SCLogInitData |
Structure containing init data, that would be passed to SCInitDebugModule() More... | |
typedef struct SCLogConfig_ | SCLogConfig |
Holds the config state used by the logging api. More... | |
Enumerations | |
enum | SCLogLevel { SC_LOG_NOTSET = -1, SC_LOG_NONE = 0, SC_LOG_EMERGENCY, SC_LOG_ALERT, SC_LOG_CRITICAL, SC_LOG_ERROR, SC_LOG_WARNING, SC_LOG_NOTICE, SC_LOG_INFO, SC_LOG_PERF, SC_LOG_CONFIG, SC_LOG_DEBUG, SC_LOG_LEVEL_MAX } |
The various log levels NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLevel() or it may result in logging to syslog with LOG_EMERG priority. More... | |
enum | SCLogOPIface { SC_LOG_OP_IFACE_CONSOLE, SC_LOG_OP_IFACE_FILE, SC_LOG_OP_IFACE_SYSLOG, SC_LOG_OP_IFACE_MAX } |
The various output interfaces supported. More... | |
enum | SCLogOPType { SC_LOG_OP_TYPE_REGULAR = 0, SC_LOG_OP_TYPE_JSON } |
Functions | |
void | SCLog (int x, const char *file, const char *func, const int line, const char *fmt,...) ATTR_FMT_PRINTF(5 |
void void | SCLogErr (int x, const char *file, const char *func, const int line, const int err, const char *fmt,...) ATTR_FMT_PRINTF(6 |
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. More... | |
SCLogOPIfaceCtx * | SCLogInitOPIfaceCtx (const char *, const char *, int, const char *) |
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 | SCLogAppendOPIfaceCtx (SCLogOPIfaceCtx *, SCLogInitData *) |
Appends an output_interface to the output_interface list sent in head. More... | |
void | SCLogInitLogModule (SCLogInitData *) |
Initializes the logging module. More... | |
void | SCLogDeInitLogModule (void) |
De-Initializes the logging module. More... | |
SCError | SCLogMessage (const SCLogLevel, const char *, const unsigned int, const char *, const SCError, const char *message) |
Adds the global log_format to the outgoing buffer. More... | |
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. More... | |
int | SCLogDebugEnabled (void) |
Returns whether debug messages are enabled to be logged or not. More... | |
void | SCLogRegisterTests (void) |
void | SCLogLoadConfig (int daemon, int verbose) |
SCLogLevel | SCLogGetLogLevel (void) |
Variables | |
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 |
Used to indicate whether the logging module has been init or not. More... | |
int | sc_log_module_cleaned |
Used to indicate whether the logging module has been cleaned or not. More... | |
Definition in file util-debug.h.
#define FatalError | ( | x, | |
... | |||
) |
Definition at line 533 of file util-debug.h.
#define FatalErrorOnInit | ( | x, | |
... | |||
) |
Fatal error IF we're starting up, and configured to consider errors to be fatal errors.
Definition at line 541 of file util-debug.h.
#define SC_LOG_DEF_LOG_FILE "suricata.log" |
Definition at line 99 of file util-debug.h.
#define SC_LOG_DEF_LOG_FORMAT_DEV "[%i] %t - (%f:%l) <%d> (%n) -- " |
Definition at line 84 of file util-debug.h.
#define SC_LOG_DEF_LOG_FORMAT_REL "%t - <%d> - " |
Definition at line 83 of file util-debug.h.
#define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO |
Definition at line 93 of file util-debug.h.
#define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE |
Definition at line 96 of file util-debug.h.
#define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0 |
Definition at line 103 of file util-debug.h.
#define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0" |
Definition at line 102 of file util-debug.h.
#define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY" |
Definition at line 42 of file util-debug.h.
#define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE" |
Definition at line 41 of file util-debug.h.
#define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT" |
Definition at line 43 of file util-debug.h.
#define SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL" |
ENV vars that can be used to set the properties for the logging module.
Definition at line 39 of file util-debug.h.
#define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER" |
Definition at line 44 of file util-debug.h.
#define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE" |
Definition at line 40 of file util-debug.h.
#define SC_LOG_FMT_FILE_NAME 'f' /* File name */ |
Definition at line 195 of file util-debug.h.
#define SC_LOG_FMT_FUNCTION 'n' /* Function */ |
Definition at line 197 of file util-debug.h.
#define SC_LOG_FMT_LINE 'l' /* Line number */ |
Definition at line 196 of file util-debug.h.
#define SC_LOG_FMT_LOG_LEVEL 'd' /* Log level */ |
Definition at line 194 of file util-debug.h.
#define SC_LOG_FMT_PID 'p' /* PID */ |
Definition at line 191 of file util-debug.h.
#define SC_LOG_FMT_PREFIX '%' |
Definition at line 200 of file util-debug.h.
#define SC_LOG_FMT_TID 'i' /* Thread ID */ |
Definition at line 192 of file util-debug.h.
#define SC_LOG_FMT_TIME 't' /* Timestamp in standard format */ |
Definition at line 190 of file util-debug.h.
Definition at line 193 of file util-debug.h.
#define SC_LOG_MAX_LOG_FORMAT_LEN 128 |
Definition at line 90 of file util-debug.h.
#define SC_LOG_MAX_LOG_MSG_LEN 2048 |
Definition at line 87 of file util-debug.h.
#define SCEnter | ( | ... | ) |
Definition at line 301 of file util-debug.h.
#define SCLogAlert | ( | err_code, | |
... | |||
) |
Macro used to log ALERT messages.
err_code | Error code that has to be logged along with the alert message |
... | Takes as argument(s), a printf style format message |
Definition at line 281 of file util-debug.h.
#define SCLogConfig | ( | ... | ) |
Definition at line 223 of file util-debug.h.
#define SCLogCritical | ( | err_code, | |
... | |||
) |
Macro used to log CRITICAL messages.
err_code | Error code that has to be logged along with the critical message |
... | Takes as argument(s), a printf style format message |
Definition at line 271 of file util-debug.h.
#define SCLogDebug | ( | ... | ) | do { } while (0) |
Definition at line 299 of file util-debug.h.
#define SCLogEmerg | ( | err_code, | |
... | |||
) |
Macro used to log EMERGENCY messages.
err_code | Error code that has to be logged along with the emergency message |
... | Takes as argument(s), a printf style format message |
Definition at line 291 of file util-debug.h.
#define SCLogError | ( | err_code, | |
... | |||
) |
Macro used to log ERROR messages.
err_code | Error code that has to be logged along with the error message |
... | Takes as argument(s), a printf style format message |
Definition at line 258 of file util-debug.h.
#define SCLogErrorRaw | ( | err_code, | |
file, | |||
func, | |||
line, | |||
... | |||
) |
Definition at line 261 of file util-debug.h.
#define SCLogInfo | ( | ... | ) |
Macro used to log INFORMATIONAL messages.
... | Takes as argument(s), a printf style format message |
Definition at line 218 of file util-debug.h.
#define SCLogInfoRaw | ( | file, | |
func, | |||
line, | |||
... | |||
) |
Definition at line 220 of file util-debug.h.
#define SCLogNotice | ( | ... | ) |
Macro used to log NOTICE messages.
... | Takes as argument(s), a printf style format message |
Definition at line 233 of file util-debug.h.
#define SCLogNoticeRaw | ( | file, | |
func, | |||
line, | |||
... | |||
) |
Definition at line 235 of file util-debug.h.
#define SCLogPerf | ( | ... | ) |
Definition at line 225 of file util-debug.h.
#define SCLogWarning | ( | err_code, | |
... | |||
) |
Macro used to log WARNING messages.
err_code | Error code that has to be logged along with the warning message |
... | Takes as argument(s), a printf style format message |
Definition at line 245 of file util-debug.h.
#define SCLogWarningRaw | ( | err_code, | |
file, | |||
func, | |||
line, | |||
... | |||
) | SCLogErr(SC_LOG_WARNING, (file), (func), (line), err_code, __VA_ARGS__) |
Definition at line 248 of file util-debug.h.
#define SCReturn return |
Definition at line 303 of file util-debug.h.
#define SCReturnBool | ( | x | ) | return x |
Definition at line 319 of file util-debug.h.
#define SCReturnChar | ( | x | ) | return x |
Definition at line 311 of file util-debug.h.
#define SCReturnCharPtr | ( | x | ) | return x |
Definition at line 313 of file util-debug.h.
#define SCReturnCT | ( | x, | |
type | |||
) | return x |
Definition at line 315 of file util-debug.h.
#define SCReturnDbl | ( | x | ) | return x |
Definition at line 309 of file util-debug.h.
#define SCReturnInt | ( | x | ) | return x |
Definition at line 305 of file util-debug.h.
#define SCReturnPtr | ( | x, | |
type | |||
) | return x |
Definition at line 317 of file util-debug.h.
#define SCReturnStruct | ( | x | ) | return x |
Definition at line 321 of file util-debug.h.
#define SCReturnUInt | ( | x | ) | return x |
Definition at line 307 of file util-debug.h.
typedef struct SCLogConfig_ SCLogConfig |
Holds the config state used by the logging api.
typedef struct SCLogInitData_ SCLogInitData |
Structure containing init data, that would be passed to SCInitDebugModule()
typedef struct SCLogOPBuffer_ SCLogOPBuffer |
Structure to be used when log_level override support would be provided by the logging module.
typedef struct SCLogOPIfaceCtx_ SCLogOPIfaceCtx |
The output interface context for the logging module.
enum SCLogLevel |
The various log levels NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLevel() or it may result in logging to syslog with LOG_EMERG priority.
Enumerator | |
---|---|
SC_LOG_NOTSET | |
SC_LOG_NONE | |
SC_LOG_EMERGENCY | |
SC_LOG_ALERT | |
SC_LOG_CRITICAL | |
SC_LOG_ERROR | |
SC_LOG_WARNING | |
SC_LOG_NOTICE | |
SC_LOG_INFO | |
SC_LOG_PERF | |
SC_LOG_CONFIG | |
SC_LOG_DEBUG | |
SC_LOG_LEVEL_MAX |
Definition at line 50 of file util-debug.h.
enum SCLogOPIface |
The various output interfaces supported.
Enumerator | |
---|---|
SC_LOG_OP_IFACE_CONSOLE | |
SC_LOG_OP_IFACE_FILE | |
SC_LOG_OP_IFACE_SYSLOG | |
SC_LOG_OP_IFACE_MAX |
Definition at line 69 of file util-debug.h.
enum SCLogOPType |
Enumerator | |
---|---|
SC_LOG_OP_TYPE_REGULAR | |
SC_LOG_OP_TYPE_JSON |
Definition at line 76 of file util-debug.h.
void SCLog | ( | int | x, |
const char * | file, | ||
const char * | func, | ||
const int | line, | ||
const char * | fmt, | ||
... | |||
) |
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.
sc_lid | Pointer to the newly created SCLogInitData \initonly |
Definition at line 1156 of file util-debug.c.
References SCMalloc.
Referenced by SCLogLoadConfig().
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.
buffer | Pointer to the newly created output_buffer |
Definition at line 681 of file util-debug.c.
References SCMalloc.
void SCLogAppendOPIfaceCtx | ( | SCLogOPIfaceCtx * | iface_ctx, |
SCLogInitData * | sc_lid | ||
) |
Appends an output_interface to the output_interface list sent in head.
iface_ctx | Pointer to the output_interface that has to be added to head |
head | Pointer to the output_interface list |
Definition at line 1219 of file util-debug.c.
References head, SCLogOPIfaceCtx_::next, SCLogInitData_::op_ifaces, and SCLogInitData_::op_ifaces_cnt.
int SCLogDebugEnabled | ( | void | ) |
Returns whether debug messages are enabled to be logged or not.
1 | if debug messages are enabled to be logged |
0 | if 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().
void SCLogDeInitLogModule | ( | void | ) |
De-Initializes the logging module.
Definition at line 1518 of file util-debug.c.
Referenced by SCLogInitLogModule().
void void SCLogErr | ( | int | x, |
const char * | file, | ||
const char * | func, | ||
const int | line, | ||
const int | err, | ||
const char * | fmt, | ||
... | |||
) |
SCLogLevel SCLogGetLogLevel | ( | void | ) |
Definition at line 974 of file util-debug.c.
References sc_log_global_log_level.
void SCLogInitLogModule | ( | SCLogInitData * | sc_lid | ) |
Initializes the logging module.
sc_lid | The 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 1304 of file util-debug.c.
References FatalError, SC_ERR_FATAL, SCLogDeInitLogModule(), and SCMutexInit.
Referenced by InitGlobal().
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.
iface_name | Interface name. Can be "console", "file" or "syslog" |
log_format | Override for the global_log_format |
log_level | Override for the global_log_level |
log_level | Parameter required by a particular interface. Explained in the function description |
iface_ctx | Pointer to the newly created output interface |
Definition at line 1264 of file util-debug.c.
References SC_LOG_DEBUG, SC_LOG_NOTSET, SC_LOG_OP_IFACE_CONSOLE, sc_log_op_iface_map, and SCMapEnumNameToValue().
void SCLogLoadConfig | ( | int | daemon, |
int | verbose | ||
) |
Definition at line 1337 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().
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.
log_level | log_level of the message that has to be logged |
msg | Buffer containing the outgoing message |
file | File_name from where the message originated |
function | Function_name from where the message originated |
line | Line_no from where the messaged originated |
SC_OK | on 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().
void SCLogRegisterTests | ( | void | ) |
Definition at line 1721 of file util-debug.c.
References UtRegisterTest().
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(), SCLogErr(), and SCLogGetLogLevel().
int sc_log_module_cleaned |
Used to indicate whether the logging module has been cleaned or not.
Definition at line 105 of file util-debug.c.
int sc_log_module_initialized |
Used to indicate whether the logging module has been init or not.
Definition at line 100 of file util-debug.c.
Referenced by SCLogMessage().