Go to the documentation of this file.
24 #ifndef SURICATA_UTIL_DEBUG_H
25 #define SURICATA_UTIL_DEBUG_H
36 #define SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL"
37 #define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE"
38 #define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE"
39 #define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY"
40 #define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT"
41 #define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER"
77 #define SC_LOG_DEF_FILE_FORMAT "[%i - %m] %z %d: %S: %M"
78 #define SC_LOG_DEF_LOG_FORMAT_REL_NOTICE "%D: %S: %M"
79 #define SC_LOG_DEF_LOG_FORMAT_REL_INFO "%d: %S: %M"
80 #define SC_LOG_DEF_LOG_FORMAT_REL_CONFIG "[%i] %d: %S: %M"
81 #define SC_LOG_DEF_LOG_FORMAT_DEBUG "%d: %S: %M [%n:%f:%l]"
84 #define SC_LOG_MAX_LOG_MSG_LEN 2048
87 #define SC_LOG_MAX_LOG_FORMAT_LEN 128
90 #define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO
93 #define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE
96 #define SC_LOG_DEF_LOG_FILE "suricata.log"
99 #define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0"
100 #define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0
187 #define SC_LOG_FMT_TIME 'z'
188 #define SC_LOG_FMT_TIME_LEGACY 't'
189 #define SC_LOG_FMT_PID 'p'
190 #define SC_LOG_FMT_TID 'i'
191 #define SC_LOG_FMT_TM 'm'
192 #define SC_LOG_FMT_LOG_LEVEL 'd'
193 #define SC_LOG_FMT_LOG_SLEVEL 'D'
194 #define SC_LOG_FMT_FILE_NAME 'f'
195 #define SC_LOG_FMT_LINE 'l'
196 #define SC_LOG_FMT_FUNCTION 'n'
197 #define SC_LOG_FMT_SUBSYSTEM 'S'
198 #define SC_LOG_FMT_THREAD_NAME 'T'
199 #define SC_LOG_FMT_MESSAGE 'M'
202 #define SC_LOG_FMT_PREFIX '%'
206 static const char *_sc_module
__attribute__((unused)) = __SCFILENAME__;
214 void SCLog(
int x,
const char *file,
const char *func,
const int line,
const char *module,
216 void SCLogErr(
int x, const
char *file, const
char *func, const
int line, const
char *module,
224 #define SCLogInfo(...) SCLog(SC_LOG_INFO, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
225 #define SCLogInfoRaw(file, func, line, ...) \
226 SCLog(SC_LOG_INFO, (file), (func), (line), _sc_module, __VA_ARGS__)
228 #define SCLogConfig(...) \
229 SCLog(SC_LOG_CONFIG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
230 #define SCLogPerf(...) SCLog(SC_LOG_PERF, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
237 #define SCLogNotice(...) \
238 SCLog(SC_LOG_NOTICE, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
239 #define SCLogNoticeRaw(file, func, line, ...) \
240 SCLog(SC_LOG_NOTICE, (file), (func), (line), _sc_module, __VA_ARGS__)
249 #define SCLogWarning(...) \
250 SCLogErr(SC_LOG_WARNING, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
251 #define SCLogWarningRaw(file, func, line, ...) \
252 SCLogErr(SC_LOG_WARNING, (file), (func), (line), _sc_module, __VA_ARGS__)
261 #define SCLogError(...) \
262 SCLogErr(SC_LOG_ERROR, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
263 #define SCLogErrorRaw(file, func, line, ...) \
264 SCLogErr(SC_LOG_ERROR, (file), (func), (line), _sc_module, __VA_ARGS__)
269 #define SCLogDebug(...) do { } while (0)
273 #define SCReturn return
275 #define SCReturnInt(x) return x
277 #define SCReturnUInt(x) return x
279 #define SCReturnDbl(x) return x
281 #define SCReturnChar(x) return x
283 #define SCReturnCharPtr(x) return x
285 #define SCReturnCT(x, type) return x
287 #define SCReturnPtr(x, type) return x
289 #define SCReturnBool(x) return x
291 #define SCReturnStruct(x) return x
303 #define SCLogDebug(...) \
304 SCLog(SC_LOG_DEBUG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
314 #define SCEnter(f) do { \
315 if (sc_log_global_log_level >= SC_LOG_DEBUG &&\
316 SCLogCheckFDFilterEntry(__FUNCTION__)) \
318 SCLogDebug("Entering ... >>"); \
330 #define SCReturn do { \
331 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
332 SCLogDebug("Returning ... <<" ); \
333 SCLogCheckFDFilterExit(__FUNCTION__); \
348 #define SCReturnInt(x) do { \
349 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
350 SCLogDebug("Returning: %"PRIdMAX" ... <<", (intmax_t)x); \
351 SCLogCheckFDFilterExit(__FUNCTION__); \
366 #define SCReturnUInt(x) do { \
367 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
368 SCLogDebug("Returning: %"PRIuMAX" ... <<", (uintmax_t)x); \
369 SCLogCheckFDFilterExit(__FUNCTION__); \
384 #define SCReturnDbl(x) do { \
385 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
386 SCLogDebug("Returning: %f ... <<", x); \
387 SCLogCheckFDFilterExit(__FUNCTION__); \
402 #define SCReturnChar(x) do { \
403 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
404 SCLogDebug("Returning: %c ... <<", x); \
405 SCLogCheckFDFilterExit(__FUNCTION__); \
420 #define SCReturnCharPtr(x) do { \
421 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
423 SCLogDebug("Returning: %s ... <<", x); \
425 SCLogDebug("Returning: NULL ... <<"); \
426 } SCLogCheckFDFilterExit(__FUNCTION__); \
443 #define SCReturnCT(x, type) do { \
444 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
445 SCLogDebug("Returning var of " \
446 "type %s ... <<", type); \
447 SCLogCheckFDFilterExit(__FUNCTION__); \
465 #define SCReturnPtr(x, type) do { \
466 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
467 SCLogDebug("Returning pointer %p of " \
468 "type %s ... <<", x, type); \
469 SCLogCheckFDFilterExit(__FUNCTION__); \
484 #define SCReturnBool(x) do { \
485 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
486 SCLogDebug("Returning: %s ... <<", x ? "true" : "false"); \
487 SCLogCheckFDFilterExit(__FUNCTION__); \
492 #define SCReturnStruct(x) do { \
493 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
494 SCLogDebug("Returning: ... <<"); \
495 SCLogCheckFDFilterExit(__FUNCTION__); \
502 #define FatalError(...) \
504 SCLogError(__VA_ARGS__); \
505 exit(EXIT_FAILURE); \
510 #if !defined(__clang_analyzer__)
511 #define FatalErrorOnInit(...) \
513 SC_ATOMIC_EXTERN(unsigned int, engine_stage); \
514 int init_errors_fatal = 0; \
515 (void)ConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
516 if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT)) { \
517 SCLogError(__VA_ARGS__); \
518 exit(EXIT_FAILURE); \
520 SCLogWarning(__VA_ARGS__); \
524 #define FatalErrorOnInit(...) FatalError(__VA_ARGS__)
527 #define BOOL2STR(b) (b) ? "true" : "false"
538 const char *message);
546 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 ...
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.
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.
void void SCLogErr(int x, const char *file, const char *func, const int line, const char *module, const char *fmt,...) ATTR_FMT_PRINTF(6
int sc_log_module_cleaned
Used to indicate whether the logging module has been cleaned or not.
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 SCLogDeInitLogModule(void)
De-Initializes the logging module.
The output interface context for the logging module.
enum @18 __attribute__
DNP3 application header.
#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.
void SCLog(int x, const char *file, const char *func, const int line, const char *module, const char *fmt,...) ATTR_FMT_PRINTF(6
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)
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.