Go to the documentation of this file.
24 #ifndef __UTIL_DEBUG_H__
25 #define __UTIL_DEBUG_H__
38 #define SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL"
39 #define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE"
40 #define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE"
41 #define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY"
42 #define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT"
43 #define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER"
82 #define SC_LOG_DEF_LOG_FORMAT_REL "%t - <%d> - "
83 #define SC_LOG_DEF_LOG_FORMAT_DEV "[%i] %t - (%f:%l) <%d> (%n) -- "
86 #define SC_LOG_MAX_LOG_MSG_LEN 2048
89 #define SC_LOG_MAX_LOG_FORMAT_LEN 128
92 #define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO
95 #define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE
98 #define SC_LOG_DEF_LOG_FILE "suricata.log"
101 #define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0"
102 #define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0
189 #define SC_LOG_FMT_TIME 't'
190 #define SC_LOG_FMT_PID 'p'
191 #define SC_LOG_FMT_TID 'i'
192 #define SC_LOG_FMT_TM 'm'
193 #define SC_LOG_FMT_LOG_LEVEL 'd'
194 #define SC_LOG_FMT_FILE_NAME 'f'
195 #define SC_LOG_FMT_LINE 'l'
196 #define SC_LOG_FMT_FUNCTION 'n'
199 #define SC_LOG_FMT_PREFIX '%'
207 void SCLog(
int x,
const char *file,
const char *func,
const int line,
209 void SCLogErr(
int x, const
char *file, const
char *func, const
int line,
217 #define SCLogInfo(...) SCLog(SC_LOG_INFO, \
218 __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
219 #define SCLogInfoRaw(file, func, line, ...) SCLog(SC_LOG_INFO, \
220 (file), (func), (line), __VA_ARGS__)
222 #define SCLogConfig(...) SCLog(SC_LOG_CONFIG, \
223 __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
224 #define SCLogPerf(...) SCLog(SC_LOG_PERF, \
225 __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
232 #define SCLogNotice(...) SCLog(SC_LOG_NOTICE, \
233 __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
234 #define SCLogNoticeRaw(file, func, line, ... ) SCLog(SC_LOG_NOTICE, \
235 (file), (func), (line), __VA_ARGS__)
244 #define SCLogWarning(err_code, ...) SCLogErr(SC_LOG_WARNING, \
245 __FILE__, __FUNCTION__, __LINE__, \
246 err_code, __VA_ARGS__)
247 #define SCLogWarningRaw(err_code, file, func, line, ...) \
248 SCLogErr(SC_LOG_WARNING, (file), (func), (line), err_code, __VA_ARGS__)
257 #define SCLogError(err_code, ...) SCLogErr(SC_LOG_ERROR, \
258 __FILE__, __FUNCTION__, __LINE__, \
259 err_code, __VA_ARGS__)
260 #define SCLogErrorRaw(err_code, file, func, line, ...) SCLogErr(SC_LOG_ERROR, \
261 (file), (func), (line), err_code, __VA_ARGS__)
270 #define SCLogCritical(err_code, ...) SCLogErr(SC_LOG_CRITICAL, \
271 __FILE__, __FUNCTION__, __LINE__, \
272 err_code, __VA_ARGS__)
280 #define SCLogAlert(err_code, ...) SCLogErr(SC_LOG_ALERT, \
281 __FILE__, __FUNCTION__, __LINE__, \
282 err_code, __VA_ARGS__)
290 #define SCLogEmerg(err_code, ...) SCLogErr(SC_LOG_EMERGENCY, \
291 __FILE__, __FUNCTION__, __LINE__, \
292 err_code, __VA_ARGS__)
298 #define SCLogDebug(...) do { } while (0)
302 #define SCReturn return
304 #define SCReturnInt(x) return x
306 #define SCReturnUInt(x) return x
308 #define SCReturnDbl(x) return x
310 #define SCReturnChar(x) return x
312 #define SCReturnCharPtr(x) return x
314 #define SCReturnCT(x, type) return x
316 #define SCReturnPtr(x, type) return x
318 #define SCReturnBool(x) return x
320 #define SCReturnStruct(x) return x
332 #define SCLogDebug(...) SCLog(SC_LOG_DEBUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
342 #define SCEnter(f) do { \
343 if (sc_log_global_log_level >= SC_LOG_DEBUG &&\
344 SCLogCheckFDFilterEntry(__FUNCTION__)) \
346 SCLogDebug("Entering ... >>"); \
359 #define SCReturn do { \
360 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
361 SCLogDebug("Returning ... <<" ); \
362 SCLogCheckFDFilterExit(__FUNCTION__); \
377 #define SCReturnInt(x) do { \
378 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
379 SCLogDebug("Returning: %"PRIdMAX" ... <<", (intmax_t)x); \
380 SCLogCheckFDFilterExit(__FUNCTION__); \
395 #define SCReturnUInt(x) do { \
396 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
397 SCLogDebug("Returning: %"PRIuMAX" ... <<", (uintmax_t)x); \
398 SCLogCheckFDFilterExit(__FUNCTION__); \
413 #define SCReturnDbl(x) do { \
414 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
415 SCLogDebug("Returning: %f ... <<", x); \
416 SCLogCheckFDFilterExit(__FUNCTION__); \
431 #define SCReturnChar(x) do { \
432 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
433 SCLogDebug("Returning: %c ... <<", x); \
434 SCLogCheckFDFilterExit(__FUNCTION__); \
449 #define SCReturnCharPtr(x) do { \
450 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
452 SCLogDebug("Returning: %s ... <<", x); \
454 SCLogDebug("Returning: NULL ... <<"); \
455 } SCLogCheckFDFilterExit(__FUNCTION__); \
473 #define SCReturnCT(x, type) do { \
474 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
475 SCLogDebug("Returning var of " \
476 "type %s ... <<", type); \
477 SCLogCheckFDFilterExit(__FUNCTION__); \
495 #define SCReturnPtr(x, type) do { \
496 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
497 SCLogDebug("Returning pointer %p of " \
498 "type %s ... <<", x, type); \
499 SCLogCheckFDFilterExit(__FUNCTION__); \
514 #define SCReturnBool(x) do { \
515 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
516 SCLogDebug("Returning: %s ... <<", x ? "true" : "false"); \
517 SCLogCheckFDFilterExit(__FUNCTION__); \
522 #define SCReturnStruct(x) do { \
523 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
524 SCLogDebug("Returning: ... <<"); \
525 SCLogCheckFDFilterExit(__FUNCTION__); \
532 #define FatalError(x, ...) do { \
533 SCLogError(x, __VA_ARGS__); \
534 exit(EXIT_FAILURE); \
539 #if !defined(__clang_analyzer__)
540 #define FatalErrorOnInit(x, ...) \
542 SC_ATOMIC_EXTERN(unsigned int, engine_stage); \
543 int init_errors_fatal = 0; \
544 (void)ConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
545 if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT)) { \
546 SCLogError(x, __VA_ARGS__); \
547 exit(EXIT_FAILURE); \
549 SCLogWarning(x, __VA_ARGS__); \
553 #define FatalErrorOnInit(x, ...) FatalError(x, __VA_ARGS__)
568 const char *,
const SCError,
const char *message);
576 void SCLogLoadConfig(
int daemon,
int verbose, uint32_t userid, uint32_t groupid);
SCLogOPIfaceCtx * op_ifaces
pcre2_match_data * op_filter_regex_match
SCLogOPBuffer * SCLogAllocLogOPBuffer(void)
Allocates an output buffer for an output interface. Used when we want the op_interface log_format to ...
void void SCLogErr(int x, const char *file, const char *func, const int line, const int err, const char *fmt,...) ATTR_FMT_PRINTF(6
void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid)
const char * global_log_format
void SCLogAppendOPIfaceCtx(SCLogOPIfaceCtx *, SCLogInitData *)
Appends an output_interface to the output_interface list sent in head.
int sc_log_module_cleaned
Used to indicate whether the logging module has been cleaned or not.
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.
Structure to be used when log_level override support would be provided by the logging module.
SCLogInitData * SCLogAllocLogInitData(void)
Returns a pointer to a new SCLogInitData. This is a public interface intended to be used after the lo...
Structure containing init data, that would be passed to SCInitDebugModule()
void SCLogInitLogModule(SCLogInitData *)
Initializes the logging module.
void SCLog(int x, const char *file, const char *func, const int line, const char *fmt,...) ATTR_FMT_PRINTF(5
void SCLogDeInitLogModule(void)
De-Initializes the logging module.
The output interface context for the logging module.
#define ATTR_FMT_PRINTF(x, y)
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
pcre2_code * op_filter_regex
SCLogLevel sc_log_global_log_level
Holds the global log level. Is the same as sc_log_config->log_level.
SCLogOPIface
The various output interfaces supported.
struct SCLogOPIfaceCtx_ SCLogOPIfaceCtx
The output interface context for the logging module.
struct SCLogOPBuffer_ SCLogOPBuffer
Structure to be used when log_level override support would be provided by the logging module.
char msg[SC_LOG_MAX_LOG_MSG_LEN]
SCLogLevel global_log_level
SCLogLevel
The various log levels NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLe...
SCLogLevel SCLogGetLogLevel(void)
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 create...
struct SCLogOPIfaceCtx_ * next
Holds the config state used by the logging api.
#define SC_LOG_MAX_LOG_MSG_LEN
void SCLogRegisterTests(void)
const char * startup_message
SCLogOPIfaceCtx * op_ifaces
struct SCLogInitData_ SCLogInitData
Structure containing init data, that would be passed to SCInitDebugModule()
@ SC_LOG_OP_IFACE_CONSOLE
int sc_log_module_initialized
Used to indicate whether the logging module has been init or not.