cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
log.h File Reference

Lightweight macro-based internal logging for CWIST. More...

#include <stddef.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CWIST_LOG(level, fmt, ...)
 Main logging macro.
 
#define CWIST_LOG_INFO(fmt, ...)   CWIST_LOG(CWIST_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
 
#define CWIST_LOG_WARN(fmt, ...)   CWIST_LOG(CWIST_LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
 
#define CWIST_LOG_ERROR(fmt, ...)   CWIST_LOG(CWIST_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
 
#define CWIST_LOG_DEBUG(fmt, ...)   CWIST_LOG(CWIST_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
 

Enumerations

enum  cwist_macro_log_level_t {
  CWIST_LOG_LEVEL_NONE = 0 , CWIST_LOG_LEVEL_DEBUG = 1 , CWIST_LOG_LEVEL_INFO = 2 , CWIST_LOG_LEVEL_WARN = 3 ,
  CWIST_LOG_LEVEL_ERROR = 4
}
 

Functions

void cwist_log_init (void)
 Initialize the logging system (e.g., set level from environment).
 
void cwist_log_write (cwist_macro_log_level_t level, const char *fmt,...)
 Write a log message to stderr.
 

Variables

cwist_macro_log_level_t g_cwist_log_level
 Global active log level. Set this to control output verbosity.
 

Detailed Description

Lightweight macro-based internal logging for CWIST.

Zero-cost when disabled: if the current global level is below the log call's level, no function call or argument evaluation occurs.

Definition in file log.h.

Macro Definition Documentation

◆ CWIST_LOG

#define CWIST_LOG (   level,
  fmt,
  ... 
)
Value:
do { \
} \
} while (0)
cwist_macro_log_level_t g_cwist_log_level
Global active log level. Set this to control output verbosity.
Definition log.c:12
@ CWIST_LOG_LEVEL_NONE
Definition log.h:19
size_t cap
Definition otel.c:56

Main logging macro.

Expands to a level check followed by a function call only when the global level is at or above the requested level. Arguments are NOT evaluated when the level is below threshold.

Definition at line 48 of file log.h.

◆ CWIST_LOG_DEBUG

#define CWIST_LOG_DEBUG (   fmt,
  ... 
)    CWIST_LOG(CWIST_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)

Definition at line 58 of file log.h.

◆ CWIST_LOG_ERROR

#define CWIST_LOG_ERROR (   fmt,
  ... 
)    CWIST_LOG(CWIST_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)

Definition at line 57 of file log.h.

◆ CWIST_LOG_INFO

#define CWIST_LOG_INFO (   fmt,
  ... 
)    CWIST_LOG(CWIST_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)

Definition at line 55 of file log.h.

◆ CWIST_LOG_WARN

#define CWIST_LOG_WARN (   fmt,
  ... 
)    CWIST_LOG(CWIST_LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)

Definition at line 56 of file log.h.

Enumeration Type Documentation

◆ cwist_macro_log_level_t

Enumerator
CWIST_LOG_LEVEL_NONE 
CWIST_LOG_LEVEL_DEBUG 
CWIST_LOG_LEVEL_INFO 
CWIST_LOG_LEVEL_WARN 
CWIST_LOG_LEVEL_ERROR 

Definition at line 18 of file log.h.

Function Documentation

◆ cwist_log_init()

void cwist_log_init ( void  )

Initialize the logging system (e.g., set level from environment).

◆ cwist_log_write()

void cwist_log_write ( cwist_macro_log_level_t  level,
const char *  fmt,
  ... 
)

Write a log message to stderr.

Parameters
levelLog level of this message.
fmtprintf-style format string.

Write a log message to stderr.

Emits one line of the form [LEVEL] [YYYY-MM-DD HH:MM:SS] <formatted message> to stderr. Unknown level values print as ???. Output is not buffered beyond the C runtime's default stderr buffering; no synchronization is performed, so interleaving may occur when called concurrently from multiple threads.

Parameters
levelSeverity tag for the record (INFO, WARN, ERROR, DEBUG, or other).
fmtprintf-style format string, followed by its arguments.

Definition at line 25 of file log.c.

References CWIST_LOG_LEVEL_DEBUG, CWIST_LOG_LEVEL_ERROR, CWIST_LOG_LEVEL_INFO, and CWIST_LOG_LEVEL_WARN.

Variable Documentation

◆ g_cwist_log_level

cwist_macro_log_level_t g_cwist_log_level
extern

Global active log level. Set this to control output verbosity.

Definition at line 12 of file log.c.