Go to the documentation of this file.
24 #ifndef SURICATA_UTIL_DEBUG_H
25 #define SURICATA_UTIL_DEBUG_H
45 #ifndef SURICATA_BINDGEN_H
55 #define SC_LOG_ENV_LOG_LEVEL "SC_LOG_LEVEL"
56 #define SC_LOG_ENV_LOG_OP_IFACE "SC_LOG_OP_IFACE"
57 #define SC_LOG_ENV_LOG_FILE "SC_LOG_FILE"
58 #define SC_LOG_ENV_LOG_FACILITY "SC_LOG_FACILITY"
59 #define SC_LOG_ENV_LOG_FORMAT "SC_LOG_FORMAT"
60 #define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER"
78 #define SC_LOG_DEF_FILE_FORMAT "[%i - %m] %z %d: %S: %M"
79 #define SC_LOG_DEF_LOG_FORMAT_REL_NOTICE "%D: %S: %M"
80 #define SC_LOG_DEF_LOG_FORMAT_REL_INFO "%d: %S: %M"
81 #define SC_LOG_DEF_LOG_FORMAT_REL_CONFIG "[%i] %d: %S: %M"
82 #define SC_LOG_DEF_LOG_FORMAT_DEBUG "%d: %S: %M [%n:%f:%l]"
85 #define SC_LOG_MAX_LOG_MSG_LEN 8192 + PATH_MAX + 512
88 #define SC_LOG_MAX_LOG_FORMAT_LEN 128
91 #define SC_LOG_DEF_LOG_LEVEL SC_LOG_INFO
94 #define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE
97 #define SC_LOG_DEF_LOG_FILE "suricata.log"
100 #define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0"
101 #define SC_LOG_DEF_SYSLOG_FACILITY LOG_LOCAL0
188 #define SC_LOG_FMT_TIME 'z'
189 #define SC_LOG_FMT_TIME_LEGACY '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_LOG_SLEVEL 'D'
195 #define SC_LOG_FMT_FILE_NAME 'f'
196 #define SC_LOG_FMT_LINE 'l'
197 #define SC_LOG_FMT_FUNCTION 'n'
198 #define SC_LOG_FMT_SUBSYSTEM 'S'
199 #define SC_LOG_FMT_THREAD_NAME 'T'
200 #define SC_LOG_FMT_MESSAGE 'M'
203 #define SC_LOG_FMT_PREFIX '%'
215 void SCLog(
int x,
const char *file,
const char *func,
const int line,
const char *module,
217 void SCLogErr(
int x, const
char *file, const
char *func, const
int line, const
char *module,
225 #define SCLogInfo(...) SCLog(SC_LOG_INFO, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
226 #define SCLogInfoRaw(file, func, line, ...) \
227 SCLog(SC_LOG_INFO, (file), (func), (line), _sc_module, __VA_ARGS__)
229 #define SCLogConfig(...) \
230 SCLog(SC_LOG_CONFIG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
231 #define SCLogConfigRaw(file, func, line, ...) \
232 SCLog(SC_LOG_CONFIG, (file), (func), (line), _sc_module, __VA_ARGS__)
234 #define SCLogPerf(...) SCLog(SC_LOG_PERF, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
235 #define SCLogPerfRaw(file, func, line, ...) \
236 SCLog(SC_LOG_PERF, (file), (func), (line), _sc_module, __VA_ARGS__)
243 #define SCLogNotice(...) \
244 SCLog(SC_LOG_NOTICE, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
245 #define SCLogNoticeRaw(file, func, line, ...) \
246 SCLog(SC_LOG_NOTICE, (file), (func), (line), _sc_module, __VA_ARGS__)
255 #define SCLogWarning(...) \
256 SCLogErr(SC_LOG_WARNING, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
257 #define SCLogWarningRaw(file, func, line, ...) \
258 SCLogErr(SC_LOG_WARNING, (file), (func), (line), _sc_module, __VA_ARGS__)
267 #define SCLogError(...) \
268 SCLogErr(SC_LOG_ERROR, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
269 #define SCLogErrorRaw(file, func, line, ...) \
270 SCLogErr(SC_LOG_ERROR, (file), (func), (line), _sc_module, __VA_ARGS__)
275 #define SCLogDebug(...) do { } while (0)
279 #define SCReturn return
281 #define SCReturnInt(x) return x
283 #define SCReturnUInt(x) return x
285 #define SCReturnDbl(x) return x
287 #define SCReturnChar(x) return x
289 #define SCReturnCharPtr(x) return x
291 #define SCReturnCT(x, type) return x
293 #define SCReturnPtr(x, type) return x
295 #define SCReturnBool(x) return x
297 #define SCReturnStruct(x) return x
309 #define SCLogDebug(...) \
310 SCLog(SC_LOG_DEBUG, __FILE__, __FUNCTION__, __LINE__, _sc_module, __VA_ARGS__)
311 #define SCLogDebugRaw(file, func, line, ...) \
312 SCLog(SC_LOG_DEBUG, (file), (func), (line), _sc_module, __VA_ARGS__)
322 #define SCEnter(f) do { \
323 if (sc_log_global_log_level >= SC_LOG_DEBUG &&\
324 SCLogCheckFDFilterEntry(__FUNCTION__)) \
326 SCLogDebug("Entering ... >>"); \
338 #define SCReturn do { \
339 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
340 SCLogDebug("Returning ... <<" ); \
341 SCLogCheckFDFilterExit(__FUNCTION__); \
356 #define SCReturnInt(x) do { \
357 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
358 SCLogDebug("Returning: %"PRIdMAX" ... <<", (intmax_t)x); \
359 SCLogCheckFDFilterExit(__FUNCTION__); \
374 #define SCReturnUInt(x) do { \
375 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
376 SCLogDebug("Returning: %"PRIuMAX" ... <<", (uintmax_t)x); \
377 SCLogCheckFDFilterExit(__FUNCTION__); \
392 #define SCReturnDbl(x) do { \
393 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
394 SCLogDebug("Returning: %f ... <<", x); \
395 SCLogCheckFDFilterExit(__FUNCTION__); \
410 #define SCReturnChar(x) do { \
411 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
412 SCLogDebug("Returning: %c ... <<", x); \
413 SCLogCheckFDFilterExit(__FUNCTION__); \
428 #define SCReturnCharPtr(x) do { \
429 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
431 SCLogDebug("Returning: %s ... <<", x); \
433 SCLogDebug("Returning: NULL ... <<"); \
434 } SCLogCheckFDFilterExit(__FUNCTION__); \
451 #define SCReturnCT(x, type) do { \
452 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
453 SCLogDebug("Returning var of " \
454 "type %s ... <<", type); \
455 SCLogCheckFDFilterExit(__FUNCTION__); \
473 #define SCReturnPtr(x, type) do { \
474 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
475 SCLogDebug("Returning pointer %p of " \
476 "type %s ... <<", x, type); \
477 SCLogCheckFDFilterExit(__FUNCTION__); \
492 #define SCReturnBool(x) do { \
493 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
494 SCLogDebug("Returning: %s ... <<", x ? "true" : "false"); \
495 SCLogCheckFDFilterExit(__FUNCTION__); \
500 #define SCReturnStruct(x) do { \
501 if (sc_log_global_log_level >= SC_LOG_DEBUG) { \
502 SCLogDebug("Returning: ... <<"); \
503 SCLogCheckFDFilterExit(__FUNCTION__); \
510 #define FatalError(...) \
512 SCLogError(__VA_ARGS__); \
513 exit(EXIT_FAILURE); \
518 #if !defined(__clang_analyzer__)
519 #define FatalErrorOnInit(...) \
521 SC_ATOMIC_EXTERN(unsigned int, engine_stage); \
522 int init_errors_fatal = 0; \
523 (void)SCConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
524 if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT)) { \
525 SCLogError(__VA_ARGS__); \
526 exit(EXIT_FAILURE); \
528 SCLogWarning(__VA_ARGS__); \
532 #define FatalErrorOnInit(...) FatalError(__VA_ARGS__)
535 #define BOOL2STR(b) (b) ? "true" : "false"
546 const char *message);
554 void SCLogLoadConfig(
int daemon,
int verbose, uint32_t userid, uint32_t groupid);
555 #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.
enum @22 __attribute__
DNP3 application header.
#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
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.