Macro

X_LOG_VERSION_MAJOR

#define X_LOG_VERSION_MAJOR 1
Macro

X_LOG_VERSION_MINOR

#define X_LOG_VERSION_MINOR 0
Macro

X_LOG_VERSION_PATCH

#define X_LOG_VERSION_PATCH 0
Macro

X_LOG_BUFFER_SIZE

Default buffer size for log messages. Can be overriden before including this header

#define X_LOG_BUFFER_SIZE(1024 *4)
Enum

XLogLevel

typedef enum{
  XLOG_LEVEL_DEBUG=0,
  XLOG_LEVEL_INFO,
  XLOG_LEVEL_WARNING,
  XLOG_LEVEL_ERROR,
  XLOG_LEVEL_FATAL,
}XLogLevel;
Enum

XLogOutputFlags

typedef enum{
  XLOG_OUTPUT_NONE=0,
  XLOG_OUTPUT_CONSOLE=1<<0,
  XLOG_OUTPUT_FILE=1<<1,
  XLOG_OUTPUT_BOTH=XLOG_OUTPUT_CONSOLE|XLOG_OUTPUT_FILE,
}XLogOutputFlags;
Enum

XLogComponent

typedef enum{
  XLOG_PLAIN=0,
  XLOG_TIMESTAMP=1<<0,
  XLOG_TAG=1<<1,
  XLOG_SOURCEINFO=1<<2,
  XLOG_DEFAULT=XLOG_TAG|XLOG_TIMESTAMP|XLOG_SOURCEINFO
}XLogComponent;
Enum

XLogColor

typedef enum{
  XLOG_COLOR_DEFAULT,
  XLOG_COLOR_BLACK,
  XLOG_COLOR_RED,
  XLOG_COLOR_GREEN,
  XLOG_COLOR_YELLOW,
  XLOG_COLOR_BLUE,
  XLOG_COLOR_MAGENTA,
  XLOG_COLOR_CYAN,
  XLOG_COLOR_WHITE,
  XLOG_COLOR_BRIGHT_BLACK,
  XLOG_COLOR_BRIGHT_RED,
  XLOG_COLOR_BRIGHT_GREEN,
  XLOG_COLOR_BRIGHT_YELLOW,
  XLOG_COLOR_BRIGHT_BLUE,
  XLOG_COLOR_BRIGHT_MAGENTA,
  XLOG_COLOR_BRIGHT_CYAN,
  XLOG_COLOR_BRIGHT_WHITE,
}XLogColor;
Function

logger_init

Initialize the logging system.

void logger_init(
 XLogOutputFlags outputs,
 XLogLevel level,
 const char *filename
);

Parameters

XLogOutputFlags outputs
Bitmask specifying enabled log outputs (console, file, etc.).
XLogLevel level
Minimum log level to emit.
const char *filename
Optional file path for file output, or NULL if unused.
Function

logger_close

Shutdown the logging system and release resources.

void logger_close(void);
Function

logger_set_console

Set the output stream used for console logging. This does not affect file logging configured via logger_init() (XLOG_OUTPUT_FILE). Passing NULL resets to stdout.

void logger_set_console(FILE *out);
Function

logger_get_console

Get the current console output stream (never NULL; defaults to stdout).

FILE * logger_get_console(void);
Function

logger_log

Emit a formatted log message with full context information.

void logger_log(
 XLogLevel level,
 XLogColor fg,
 XLogColor bg,
 XLogComponent components,
 const char *file,
 int line,
 const char *func,
 const char *fmt,
 ...
);

Parameters

XLogLevel level
Log severity level.
XLogColor fg
Foreground color.
XLogColor bg
Background color.
XLogComponent components
Bitmask controlling which components (timestamp, file, line, etc.) are included.
const char *file
Source file name.
int line
Source line number.
const char *func
Source function name.
const char *fmt
printf-style format string.
Function

logger_log_to

Emit a formatted log message with full context information, overriding the console output stream. If console output is enabled (XLOG_OUTPUT_CONSOLE), the message is written to `out` when non-NULL. If `out` is NULL, the logger's default console stream is used. File output configured via logger_init() is still honored when XLOG_OUTPUT_FILE is enabled.

void logger_log_to(
 FILE *out,
 XLogLevel level,
 XLogColor fg,
 XLogColor bg,
 XLogComponent components,
 const char *file,
 int line,
 const char *func,
 const char *fmt,
 ...
);
Function

logger_print

Emit a formatted log message without source context.

void logger_print(
 XLogLevel level,
 const char *fmt,
 ...
);

Parameters

XLogLevel level
Log severity level.
const char *fmt
printf-style format string.
Macro

X_LOG_BREAK

#define X_LOG_BREAK() ((void)0)
Macro

x_log_raw

Emit a raw log message with explicit formatting and components. Automatically injects source file, line, and function information.

#define x_log_raw(out, level, fg, bg, components, fmt, ...) \
logger_log_to(out, level, fg, bg, components, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__)
Macro

x_log_debug

Emit a debug-level log message.

#define x_log_debug(fmt, ...) \
logger_log(XLOG_LEVEL_DEBUG, XLOG_COLOR_BLUE, XLOG_COLOR_BLACK, XLOG_DEFAULT, __FILE__, __LINE__, __func__, (const char *)fmt "\n", ##__VA_ARGS__)
Macro

x_log_info

Emit an informational log message with timestamp.

#define x_log_info(fmt, ...) \
logger_log(XLOG_LEVEL_INFO, XLOG_COLOR_WHITE, XLOG_COLOR_BLACK, XLOG_TIMESTAMP, __FILE__, __LINE__, __func__, (const char *)fmt "\n", ##__VA_ARGS__)
Macro

x_log_warning

Emit a warning-level log message.

#define x_log_warning(fmt, ...) \
logger_log(XLOG_LEVEL_WARNING, XLOG_COLOR_YELLOW, XLOG_COLOR_BLACK, XLOG_DEFAULT, __FILE__, __LINE__, __func__, (const char *)fmt "\n", ##__VA_ARGS__)
Macro

x_log_error

Emit an error-level log message.

#define x_log_error(fmt, ...) \
logger_log(XLOG_LEVEL_ERROR, XLOG_COLOR_RED, XLOG_COLOR_BLACK, XLOG_DEFAULT, __FILE__, __LINE__, __func__, (const char *)fmt "\n", ##__VA_ARGS__)
Macro

x_log_fatal

Emit a fatal log message and trigger a break action. Calls X_LOG_BREAK() after logging.

#define x_log_fatal(fmt, ...) \
do{\
logger_log(XLOG_LEVEL_FATAL, XLOG_COLOR_WHITE, XLOG_COLOR_RED, XLOG_DEFAULT, __FILE__, __LINE__, __func__, (const char *)fmt "\n", ##__VA_ARGS__);\
X_LOG_BREAK();\
}while(0)