suricata
|
#include "suricata-common.h"
#include "threads.h"
#include "util-error.h"
#include "util-debug-filters.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_FILE_FORMAT "[%i - %m] %z %d: %S: %M" |
#define | SC_LOG_DEF_LOG_FORMAT_REL_NOTICE "%D: %S: %M" |
#define | SC_LOG_DEF_LOG_FORMAT_REL_INFO "%d: %S: %M" |
#define | SC_LOG_DEF_LOG_FORMAT_REL_CONFIG "[%i] %d: %S: %M" |
#define | SC_LOG_DEF_LOG_FORMAT_DEBUG "%d: %S: %M [%n:%f:%l]" |
#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 'z' /* Timestamp in RFC3339 like format */ |
#define | SC_LOG_FMT_TIME_LEGACY 't' /* Timestamp in legacy 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_LOG_SLEVEL '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_SUBSYSTEM 'S' /* Subsystem name */ |
#define | SC_LOG_FMT_THREAD_NAME 'T' /* thread name */ |
#define | SC_LOG_FMT_MESSAGE 'M' /* log message body */ |
#define | SC_LOG_FMT_PREFIX '%' |
#define | SCLogInfo(...) SCLog(SC_LOG_INFO, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Macro used to log INFORMATIONAL messages. More... | |
#define | SCLogInfoRaw(file, func, line, ...) SCLog(SC_LOG_INFO, (file), (func), (line), _sc_module, __VA_ARGS__) |
#define | SCLogConfig(...) SCLog(SC_LOG_CONFIG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
#define | SCLogPerf(...) SCLog(SC_LOG_PERF, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
#define | SCLogNotice(...) SCLog(SC_LOG_NOTICE, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Macro used to log NOTICE messages. More... | |
#define | SCLogNoticeRaw(file, func, line, ...) SCLog(SC_LOG_NOTICE, (file), (func), (line), _sc_module, __VA_ARGS__) |
#define | SCLogWarning(...) SCLogErr(SC_LOG_WARNING, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Macro used to log WARNING messages. More... | |
#define | SCLogWarningRaw(file, func, line, ...) SCLogErr(SC_LOG_WARNING, (file), (func), (line), _sc_module, __VA_ARGS__) |
#define | SCLogError(...) SCLogErr(SC_LOG_ERROR, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Macro used to log ERROR messages. More... | |
#define | SCLogErrorRaw(file, func, line, ...) SCLogErr(SC_LOG_ERROR, (file), (func), (line), _sc_module, __VA_ARGS__) |
#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(...) |
#define | FatalErrorOnInit(...) |
Fatal error IF we're starting up, and configured to consider errors to be fatal errors. More... | |
#define | BOOL2STR(b) (b) ? "true" : "false" |
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_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 *module, const char *fmt,...) ATTR_FMT_PRINTF(6 |
void void | SCLogErr (int x, const char *file, const char *func, const int line, const char *module, 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 parameters are read from the conf file. 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 char *, 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, uint32_t userid, uint32_t groupid) |
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 BOOL2STR | ( | b | ) | (b) ? "true" : "false" |
Definition at line 528 of file util-debug.h.
#define FatalError | ( | ... | ) |
Definition at line 503 of file util-debug.h.
#define FatalErrorOnInit | ( | ... | ) |
Fatal error IF we're starting up, and configured to consider errors to be fatal errors.
Definition at line 512 of file util-debug.h.
#define SC_LOG_DEF_FILE_FORMAT "[%i - %m] %z %d: %S: %M" |
Definition at line 78 of file util-debug.h.
#define SC_LOG_DEF_LOG_FILE "suricata.log" |
Definition at line 97 of file util-debug.h.
#define SC_LOG_DEF_LOG_FORMAT_DEBUG "%d: %S: %M [%n:%f:%l]" |
Definition at line 82 of file util-debug.h.
#define SC_LOG_DEF_LOG_FORMAT_REL_CONFIG "[%i] %d: %S: %M" |
Definition at line 81 of file util-debug.h.
#define SC_LOG_DEF_LOG_FORMAT_REL_INFO "%d: %S: %M" |
Definition at line 80 of file util-debug.h.
#define SC_LOG_DEF_LOG_FORMAT_REL_NOTICE "%D: %S: %M" |
Definition at line 79 of file util-debug.h.
#define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO |
Definition at line 91 of file util-debug.h.
#define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE |
Definition at line 94 of file util-debug.h.
#define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0 |
Definition at line 101 of file util-debug.h.
#define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0" |
Definition at line 100 of file util-debug.h.
#define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY" |
Definition at line 40 of file util-debug.h.
#define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE" |
Definition at line 39 of file util-debug.h.
#define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT" |
Definition at line 41 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 37 of file util-debug.h.
#define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER" |
Definition at line 42 of file util-debug.h.
#define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE" |
Definition at line 38 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 193 of file util-debug.h.
#define SC_LOG_FMT_LOG_SLEVEL 'D' /* Log level */ |
Definition at line 194 of file util-debug.h.
#define SC_LOG_FMT_MESSAGE 'M' /* log message body */ |
Definition at line 200 of file util-debug.h.
#define SC_LOG_FMT_PID 'p' /* PID */ |
Definition at line 190 of file util-debug.h.
#define SC_LOG_FMT_PREFIX '%' |
Definition at line 203 of file util-debug.h.
#define SC_LOG_FMT_SUBSYSTEM 'S' /* Subsystem name */ |
Definition at line 198 of file util-debug.h.
#define SC_LOG_FMT_THREAD_NAME 'T' /* thread name */ |
Definition at line 199 of file util-debug.h.
#define SC_LOG_FMT_TID 'i' /* Thread ID */ |
Definition at line 191 of file util-debug.h.
#define SC_LOG_FMT_TIME 'z' /* Timestamp in RFC3339 like format */ |
Definition at line 188 of file util-debug.h.
#define SC_LOG_FMT_TIME_LEGACY 't' /* Timestamp in legacy format */ |
Definition at line 189 of file util-debug.h.
Definition at line 192 of file util-debug.h.
#define SC_LOG_MAX_LOG_FORMAT_LEN 128 |
Definition at line 88 of file util-debug.h.
#define SC_LOG_MAX_LOG_MSG_LEN 2048 |
Definition at line 85 of file util-debug.h.
#define SCEnter | ( | ... | ) |
Definition at line 272 of file util-debug.h.
#define SCLogConfig | ( | ... | ) | SCLog(SC_LOG_CONFIG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Definition at line 229 of file util-debug.h.
#define SCLogDebug | ( | ... | ) | do { } while (0) |
Definition at line 270 of file util-debug.h.
#define SCLogError | ( | ... | ) | SCLogErr(SC_LOG_ERROR, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
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 262 of file util-debug.h.
#define SCLogErrorRaw | ( | file, | |
func, | |||
line, | |||
... | |||
) | SCLogErr(SC_LOG_ERROR, (file), (func), (line), _sc_module, __VA_ARGS__) |
Definition at line 264 of file util-debug.h.
#define SCLogInfo | ( | ... | ) | SCLog(SC_LOG_INFO, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Macro used to log INFORMATIONAL messages.
... | Takes as argument(s), a printf style format message |
Definition at line 225 of file util-debug.h.
#define SCLogInfoRaw | ( | file, | |
func, | |||
line, | |||
... | |||
) | SCLog(SC_LOG_INFO, (file), (func), (line), _sc_module, __VA_ARGS__) |
Definition at line 226 of file util-debug.h.
#define SCLogNotice | ( | ... | ) | SCLog(SC_LOG_NOTICE, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Macro used to log NOTICE messages.
... | Takes as argument(s), a printf style format message |
Definition at line 238 of file util-debug.h.
#define SCLogNoticeRaw | ( | file, | |
func, | |||
line, | |||
... | |||
) | SCLog(SC_LOG_NOTICE, (file), (func), (line), _sc_module, __VA_ARGS__) |
Definition at line 240 of file util-debug.h.
#define SCLogPerf | ( | ... | ) | SCLog(SC_LOG_PERF, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
Definition at line 231 of file util-debug.h.
#define SCLogWarning | ( | ... | ) | SCLogErr(SC_LOG_WARNING, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__) |
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 250 of file util-debug.h.
#define SCLogWarningRaw | ( | file, | |
func, | |||
line, | |||
... | |||
) | SCLogErr(SC_LOG_WARNING, (file), (func), (line), _sc_module, __VA_ARGS__) |
Definition at line 252 of file util-debug.h.
#define SCReturn return |
Definition at line 274 of file util-debug.h.
#define SCReturnBool | ( | x | ) | return x |
Definition at line 290 of file util-debug.h.
#define SCReturnChar | ( | x | ) | return x |
Definition at line 282 of file util-debug.h.
#define SCReturnCharPtr | ( | x | ) | return x |
Definition at line 284 of file util-debug.h.
#define SCReturnCT | ( | x, | |
type | |||
) | return x |
Definition at line 286 of file util-debug.h.
#define SCReturnDbl | ( | x | ) | return x |
Definition at line 280 of file util-debug.h.
#define SCReturnInt | ( | x | ) | return x |
Definition at line 276 of file util-debug.h.
#define SCReturnPtr | ( | x, | |
type | |||
) | return x |
Definition at line 288 of file util-debug.h.
#define SCReturnStruct | ( | x | ) | return x |
Definition at line 292 of file util-debug.h.
#define SCReturnUInt | ( | x | ) | return x |
Definition at line 278 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_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 48 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 64 of file util-debug.h.
enum SCLogOPType |
Enumerator | |
---|---|
SC_LOG_OP_TYPE_REGULAR | |
SC_LOG_OP_TYPE_JSON |
Definition at line 71 of file util-debug.h.
void SCLog | ( | int | x, |
const char * | file, | ||
const char * | func, | ||
const int | line, | ||
const char * | module, | ||
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 parameters are read from the conf file.
sc_lid | Pointer to the newly created SCLogInitData \initonly |
Definition at line 1250 of file util-debug.c.
References SCCalloc.
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 786 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 1306 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 767 of file util-debug.c.
References SC_LOG_DEBUG, and sc_log_global_log_level.
Referenced by FlowVarPrint().
void SCLogDeInitLogModule | ( | void | ) |
De-Initializes the logging module.
Definition at line 1597 of file util-debug.c.
Referenced by GlobalsDestroy(), and SCLogInitLogModule().
void void SCLogErr | ( | int | x, |
const char * | file, | ||
const char * | func, | ||
const int | line, | ||
const char * | module, | ||
const char * | fmt, | ||
... | |||
) |
SCLogLevel SCLogGetLogLevel | ( | void | ) |
Definition at line 1070 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 1390 of file util-debug.c.
References FatalError, SCLogDeInitLogModule(), and SCMutexInit.
Referenced by InitGlobal().
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().
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.
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 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().
void SCLogRegisterTests | ( | void | ) |
Definition at line 1799 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 101 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 111 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 106 of file util-debug.c.
Referenced by SCLogMessage().