Go to the documentation of this file.
24 #ifndef SURICATA_UTIL_DEBUG_H
25 #define SURICATA_UTIL_DEBUG_H
53 #ifndef SURICATA_BINDGEN_H
62 #define SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL"
63 #define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE"
64 #define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE"
65 #define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY"
66 #define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT"
67 #define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER"
85 #define SC_LOG_DEF_FILE_FORMAT "[%i - %m] %z %d: %S: %M"
86 #define SC_LOG_DEF_LOG_FORMAT_REL_NOTICE "%D: %S: %M"
87 #define SC_LOG_DEF_LOG_FORMAT_REL_INFO "%d: %S: %M"
88 #define SC_LOG_DEF_LOG_FORMAT_REL_CONFIG "[%i] %d: %S: %M"
89 #define SC_LOG_DEF_LOG_FORMAT_DEBUG "%d: %S: %M [%n:%f:%l]"
92 #define SC_LOG_MAX_LOG_MSG_LEN 8192 + PATH_MAX + 512
95 #define SC_LOG_MAX_LOG_FORMAT_LEN 128
98 #define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO
101 #define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE
104 #define SC_LOG_DEF_LOG_FILE "suricata.log"
107 #define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0"
108 #define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0
195 #define SC_LOG_FMT_TIME 'z'
196 #define SC_LOG_FMT_TIME_LEGACY 't'
197 #define SC_LOG_FMT_PID 'p'
198 #define SC_LOG_FMT_TID 'i'
199 #define SC_LOG_FMT_TM 'm'
200 #define SC_LOG_FMT_LOG_LEVEL 'd'
201 #define SC_LOG_FMT_LOG_SLEVEL 'D'
202 #define SC_LOG_FMT_FILE_NAME 'f'
203 #define SC_LOG_FMT_LINE 'l'
204 #define SC_LOG_FMT_FUNCTION 'n'
205 #define SC_LOG_FMT_SUBSYSTEM 'S'
206 #define SC_LOG_FMT_THREAD_NAME 'T'
207 #define SC_LOG_FMT_MESSAGE 'M'
210 #define SC_LOG_FMT_PREFIX '%'
222 void SCLog(
int x,
const char *file,
const char *func,
const int line,
const char *module,
224 void SCLogErr(
int x, const
char *file, const
char *func, const
int line, const
char *module,
232 #define SCLogInfo(...) SCLog(SC_LOG_INFO, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
233 #define SCLogInfoRaw(file, func, line, ...) \
234 SCLog(SC_LOG_INFO, (file), (func), (line), _sc_module, __VA_ARGS__)
236 #define SCLogConfig(...) \
237 SCLog(SC_LOG_CONFIG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
238 #define SCLogConfigRaw(file, func, line, ...) \
239 SCLog(SC_LOG_CONFIG, (file), (func), (line), _sc_module, __VA_ARGS__)
241 #define SCLogPerf(...) SCLog(SC_LOG_PERF, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
242 #define SCLogPerfRaw(file, func, line, ...) \
243 SCLog(SC_LOG_PERF, (file), (func), (line), _sc_module, __VA_ARGS__)
250 #define SCLogNotice(...) \
251 SCLog(SC_LOG_NOTICE, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
252 #define SCLogNoticeRaw(file, func, line, ...) \
253 SCLog(SC_LOG_NOTICE, (file), (func), (line), _sc_module, __VA_ARGS__)
262 #define SCLogWarning(...) \
263 SCLogErr(SC_LOG_WARNING, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
264 #define SCLogWarningRaw(file, func, line, ...) \
265 SCLogErr(SC_LOG_WARNING, (file), (func), (line), _sc_module, __VA_ARGS__)
274 #define SCLogError(...) \
275 SCLogErr(SC_LOG_ERROR, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
276 #define SCLogErrorRaw(file, func, line, ...) \
277 SCLogErr(SC_LOG_ERROR, (file), (func), (line), _sc_module, __VA_ARGS__)
282 #define SCLogDebug(...) do { } while (0)
286 #define SCReturn return
288 #define SCReturnInt(x) return x
290 #define SCReturnUInt(x) return x
292 #define SCReturnDbl(x) return x
294 #define SCReturnChar(x) return x
296 #define SCReturnCharPtr(x) return x
298 #define SCReturnCT(x, type) return x
300 #define SCReturnPtr(x, type) return x
302 #define SCReturnBool(x) return x
304 #define SCReturnStruct(x) return x
316 #define SCLogDebug(...) \
317 SCLog(SC_LOG_DEBUG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
318 #define SCLogDebugRaw(file, func, line, ...) \
319 SCLog(SC_LOG_DEBUG, (file), (func), (line), _sc_module, __VA_ARGS__)
329 #define SCEnter(f) do { \
330 if (sc_log_global_log_level >= SC_LOG_DEBUG &&\
331 SCLogCheckFDFilterEntry(__FUNCTION__)) \
333 SCLogDebug("Entering ... >>"); \
345 #define SCReturn do { \
346 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
347 SCLogDebug("Returning ... <<" ); \
348 SCLogCheckFDFilterExit(__FUNCTION__); \
363 #define SCReturnInt(x) do { \
364 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
365 SCLogDebug("Returning: %"PRIdMAX" ... <<", (intmax_t)x); \
366 SCLogCheckFDFilterExit(__FUNCTION__); \
381 #define SCReturnUInt(x) do { \
382 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
383 SCLogDebug("Returning: %"PRIuMAX" ... <<", (uintmax_t)x); \
384 SCLogCheckFDFilterExit(__FUNCTION__); \
399 #define SCReturnDbl(x) do { \
400 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
401 SCLogDebug("Returning: %f ... <<", x); \
402 SCLogCheckFDFilterExit(__FUNCTION__); \
417 #define SCReturnChar(x) do { \
418 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
419 SCLogDebug("Returning: %c ... <<", x); \
420 SCLogCheckFDFilterExit(__FUNCTION__); \
435 #define SCReturnCharPtr(x) do { \
436 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
438 SCLogDebug("Returning: %s ... <<", x); \
440 SCLogDebug("Returning: NULL ... <<"); \
441 } SCLogCheckFDFilterExit(__FUNCTION__); \
458 #define SCReturnCT(x, type) do { \
459 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
460 SCLogDebug("Returning var of " \
461 "type %s ... <<", type); \
462 SCLogCheckFDFilterExit(__FUNCTION__); \
480 #define SCReturnPtr(x, type) do { \
481 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
482 SCLogDebug("Returning pointer %p of " \
483 "type %s ... <<", x, type); \
484 SCLogCheckFDFilterExit(__FUNCTION__); \
499 #define SCReturnBool(x) do { \
500 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
501 SCLogDebug("Returning: %s ... <<", x ? "true" : "false"); \
502 SCLogCheckFDFilterExit(__FUNCTION__); \
507 #define SCReturnStruct(x) do { \
508 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
509 SCLogDebug("Returning: ... <<"); \
510 SCLogCheckFDFilterExit(__FUNCTION__); \
517 #define FatalError(...) \
519 SCLogError(__VA_ARGS__); \
520 exit(EXIT_FAILURE); \
525 #if !defined(__clang_analyzer__)
526 #define FatalErrorOnInit(...) \
528 SC_ATOMIC_EXTERN(unsigned int, engine_stage); \
529 int init_errors_fatal = 0; \
530 (void)SCConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
531 if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT)) { \
532 SCLogError(__VA_ARGS__); \
533 exit(EXIT_FAILURE); \
535 SCLogWarning(__VA_ARGS__); \
539 #define FatalErrorOnInit(...) FatalError(__VA_ARGS__)
542 #define BOOL2STR(b) (b) ? "true" : "false"
558 void SCLogLoadConfig(
int daemon,
int verbose, uint32_t userid, uint32_t groupid);
559 #endif // #ifndef SURICATA_BINDGEN_H
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.
const char * SCLogLevel2Name(const SCLogLevel lvl)
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.
#define ATTR_FMT_PRINTF(x, y)
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
void SCFatalErrorOnInitStatic(const char *)
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
typedef __attribute__
DNP3 application header.
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.