LibTMJ 1.4.0
A library for loading JSON Tiled maps
Loading...
Searching...
No Matches
log.c
Go to the documentation of this file.
1#include <stdarg.h>
2#include <stdbool.h>
3#include <stdio.h>
4
5#include "../include/tmj.h"
6
11#define LOGMSG_BUFSIZE 1024
12
13bool log_debug = false;
14void (*log_callback)(tmj_log_priority, const char*) = NULL;
15
17
18void tmj_log_regcb(bool debug, void (*callback)(tmj_log_priority, const char*)) {
19 log_debug = debug;
20 log_callback = callback;
21}
22
23void logmsg(tmj_log_priority priority, char* msg, ...) {
24 // Don't bother logging if there's no callback registered
25 if (log_callback == NULL) {
26 return;
27 }
28
29 // Don't log debug messages if we have debugging turned off
30 if (priority == TMJ_LOG_DEBUG && !log_debug) {
31 return;
32 }
33
34 va_list args;
35
36 va_start(args, msg);
37
38 vsnprintf(logmsg_buf, LOGMSG_BUFSIZE, msg, args); // NOLINT(clang-analyzer-valist.Uninitialized)
39
40 va_end(args);
41
42 log_callback(priority, logmsg_buf);
43}
void logmsg(tmj_log_priority priority, char *msg,...)
Processes log messages and passes them to the active logging callback, if there is one.
Definition log.c:23
char logmsg_buf[LOGMSG_BUFSIZE]
Statically-allocated memory to hold log messages which are passed to the logging callback.
Definition log.c:16
enum TMJ_LOG_PRIORITY tmj_log_priority
void tmj_log_regcb(bool debug, void(*callback)(tmj_log_priority, const char *))
Registers a callback function to handle logging events.
Definition log.c:18
@ TMJ_LOG_DEBUG
Definition tmj.h:499
#define LOGMSG_BUFSIZE
Definition log.c:11
bool log_debug
Definition log.c:13
void(* log_callback)(tmj_log_priority, const char *)
Definition log.c:14