Go to the documentation of this file.
24 #ifndef SURICATA_UTIL_DEBUG_H
25 #define SURICATA_UTIL_DEBUG_H
50 #ifndef SURICATA_BINDGEN_H
59 #define SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL"
60 #define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE"
61 #define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE"
62 #define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY"
63 #define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT"
64 #define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER"
82 #define SC_LOG_DEF_FILE_FORMAT "[%i - %m] %z %d: %S: %M"
83 #define SC_LOG_DEF_LOG_FORMAT_REL_NOTICE "%D: %S: %M"
84 #define SC_LOG_DEF_LOG_FORMAT_REL_INFO "%d: %S: %M"
85 #define SC_LOG_DEF_LOG_FORMAT_REL_CONFIG "[%i] %d: %S: %M"
86 #define SC_LOG_DEF_LOG_FORMAT_DEBUG "%d: %S: %M [%n:%f:%l]"
89 #define SC_LOG_MAX_LOG_MSG_LEN 8192 + PATH_MAX + 512
92 #define SC_LOG_MAX_LOG_FORMAT_LEN 128
95 #define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO
98 #define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE
101 #define SC_LOG_DEF_LOG_FILE "suricata.log"
104 #define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0"
105 #define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0
192 #define SC_LOG_FMT_TIME 'z'
193 #define SC_LOG_FMT_TIME_LEGACY 't'
194 #define SC_LOG_FMT_PID 'p'
195 #define SC_LOG_FMT_TID 'i'
196 #define SC_LOG_FMT_TM 'm'
197 #define SC_LOG_FMT_LOG_LEVEL 'd'
198 #define SC_LOG_FMT_LOG_SLEVEL 'D'
199 #define SC_LOG_FMT_FILE_NAME 'f'
200 #define SC_LOG_FMT_LINE 'l'
201 #define SC_LOG_FMT_FUNCTION 'n'
202 #define SC_LOG_FMT_SUBSYSTEM 'S'
203 #define SC_LOG_FMT_THREAD_NAME 'T'
204 #define SC_LOG_FMT_MESSAGE 'M'
207 #define SC_LOG_FMT_PREFIX '%'
219 void SCLog(
int x,
const char *file,
const char *func,
const int line,
const char *module,
221 void SCLogErr(
int x, const
char *file, const
char *func, const
int line, const
char *module,
229 #define SCLogInfo(...) SCLog(SC_LOG_INFO, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
230 #define SCLogInfoRaw(file, func, line, ...) \
231 SCLog(SC_LOG_INFO, (file), (func), (line), _sc_module, __VA_ARGS__)
233 #define SCLogConfig(...) \
234 SCLog(SC_LOG_CONFIG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
235 #define SCLogConfigRaw(file, func, line, ...) \
236 SCLog(SC_LOG_CONFIG, (file), (func), (line), _sc_module, __VA_ARGS__)
238 #define SCLogPerf(...) SCLog(SC_LOG_PERF, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
239 #define SCLogPerfRaw(file, func, line, ...) \
240 SCLog(SC_LOG_PERF, (file), (func), (line), _sc_module, __VA_ARGS__)
247 #define SCLogNotice(...) \
248 SCLog(SC_LOG_NOTICE, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
249 #define SCLogNoticeRaw(file, func, line, ...) \
250 SCLog(SC_LOG_NOTICE, (file), (func), (line), _sc_module, __VA_ARGS__)
259 #define SCLogWarning(...) \
260 SCLogErr(SC_LOG_WARNING, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
261 #define SCLogWarningRaw(file, func, line, ...) \
262 SCLogErr(SC_LOG_WARNING, (file), (func), (line), _sc_module, __VA_ARGS__)
271 #define SCLogError(...) \
272 SCLogErr(SC_LOG_ERROR, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
273 #define SCLogErrorRaw(file, func, line, ...) \
274 SCLogErr(SC_LOG_ERROR, (file), (func), (line), _sc_module, __VA_ARGS__)
279 #define SCLogDebug(...) do { } while (0)
283 #define SCReturn return
285 #define SCReturnInt(x) return x
287 #define SCReturnUInt(x) return x
289 #define SCReturnDbl(x) return x
291 #define SCReturnChar(x) return x
293 #define SCReturnCharPtr(x) return x
295 #define SCReturnCT(x, type) return x
297 #define SCReturnPtr(x, type) return x
299 #define SCReturnBool(x) return x
301 #define SCReturnStruct(x) return x
313 #define SCLogDebug(...) \
314 SCLog(SC_LOG_DEBUG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
315 #define SCLogDebugRaw(file, func, line, ...) \
316 SCLog(SC_LOG_DEBUG, (file), (func), (line), _sc_module, __VA_ARGS__)
326 #define SCEnter(f) do { \
327 if (sc_log_global_log_level >= SC_LOG_DEBUG &&\
328 SCLogCheckFDFilterEntry(__FUNCTION__)) \
330 SCLogDebug("Entering ... >>"); \
342 #define SCReturn do { \
343 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
344 SCLogDebug("Returning ... <<" ); \
345 SCLogCheckFDFilterExit(__FUNCTION__); \
360 #define SCReturnInt(x) do { \
361 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
362 SCLogDebug("Returning: %"PRIdMAX" ... <<", (intmax_t)x); \
363 SCLogCheckFDFilterExit(__FUNCTION__); \
378 #define SCReturnUInt(x) do { \
379 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
380 SCLogDebug("Returning: %"PRIuMAX" ... <<", (uintmax_t)x); \
381 SCLogCheckFDFilterExit(__FUNCTION__); \
396 #define SCReturnDbl(x) do { \
397 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
398 SCLogDebug("Returning: %f ... <<", x); \
399 SCLogCheckFDFilterExit(__FUNCTION__); \
414 #define SCReturnChar(x) do { \
415 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
416 SCLogDebug("Returning: %c ... <<", x); \
417 SCLogCheckFDFilterExit(__FUNCTION__); \
432 #define SCReturnCharPtr(x) do { \
433 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
435 SCLogDebug("Returning: %s ... <<", x); \
437 SCLogDebug("Returning: NULL ... <<"); \
438 } SCLogCheckFDFilterExit(__FUNCTION__); \
455 #define SCReturnCT(x, type) do { \
456 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
457 SCLogDebug("Returning var of " \
458 "type %s ... <<", type); \
459 SCLogCheckFDFilterExit(__FUNCTION__); \
477 #define SCReturnPtr(x, type) do { \
478 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
479 SCLogDebug("Returning pointer %p of " \
480 "type %s ... <<", x, type); \
481 SCLogCheckFDFilterExit(__FUNCTION__); \
496 #define SCReturnBool(x) do { \
497 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
498 SCLogDebug("Returning: %s ... <<", x ? "true" : "false"); \
499 SCLogCheckFDFilterExit(__FUNCTION__); \
504 #define SCReturnStruct(x) do { \
505 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
506 SCLogDebug("Returning: ... <<"); \
507 SCLogCheckFDFilterExit(__FUNCTION__); \
514 #define FatalError(...) \
516 SCLogError(__VA_ARGS__); \
517 exit(EXIT_FAILURE); \
522 #if !defined(__clang_analyzer__)
523 #define FatalErrorOnInit(...) \
525 SC_ATOMIC_EXTERN(unsigned int, engine_stage); \
526 int init_errors_fatal = 0; \
527 (void)SCConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
528 if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT)) { \
529 SCLogError(__VA_ARGS__); \
530 exit(EXIT_FAILURE); \
532 SCLogWarning(__VA_ARGS__); \
536 #define FatalErrorOnInit(...) FatalError(__VA_ARGS__)
539 #define BOOL2STR(b) (b) ? "true" : "false"
555 void SCLogLoadConfig(
int daemon,
int verbose, uint32_t userid, uint32_t groupid);
556 #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.
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.