Banjo API
1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
logging.c
Go to the documentation of this file.
1
10
11
#include <
banjo/assert.h
>
12
#include <
banjo/main.h
>
13
#include <
banjo/log.h
>
14
15
int
main
(
int
argc,
char
* argv[]) {
16
(void)argc;
17
(void)argv;
18
19
// Banjo has six log levels in ascending severity:
20
// BJ_LOG_TRACE (0) - Detailed trace information
21
// BJ_LOG_DEBUG (1) - Debug information
22
// BJ_LOG_INFO (2) - Informational messages
23
// BJ_LOG_WARN (3) - Warning messages
24
// BJ_LOG_ERROR (4) - Error messages
25
// BJ_LOG_FATAL (5) - Fatal error messages
26
//
27
// The default level is TRACE (0), which displays all messages.
28
const
int
default_level =
bj_get_log_level
();
29
bj_assert
(default_level == 0);
30
bj_info
(
"Default log level: %d\n"
, default_level);
31
32
// Change the minimum severity level that will be displayed. Messages below
33
// this level are silently discarded. Here we set it to INFO, so TRACE and
34
// DEBUG messages won't appear.
35
bj_set_log_level
(
BJ_LOG_INFO
);
36
37
// The generic bj_log_msg(level, ...) function logs at any severity.
38
// Only messages at or above the current level (INFO) will display.
39
bj_log_msg
(TRACE,
"Trace level (won't display)"
);
40
bj_log_msg
(INFO,
"Information level message"
);
41
bj_log_msg
(WARN,
"Warning level message"
);
42
43
// Convenience functions are provided for each level: bj_trace(), bj_debug(),
44
// bj_info(), bj_warn(), bj_err(), bj_fatal(). These are clearer than using
45
// the generic bj_log_msg().
46
bj_err
(
"This is an error message"
);
47
48
// All logging functions support printf-style formatting with variable
49
// arguments. They return the number of characters written (excluding the
50
// null terminator), which can be useful for buffer management or testing.
51
size_t
written =
bj_warn
(
"Room #%d is closed, but you have '%s'"
, 42,
"The Key Item"
);
52
53
bj_info
(
"Previous log message was written in %ld characters (excluding '\\0')"
, written);
54
return
0;
55
}
assert.h
Assertion facility for Banjo API.
bj_assert
#define bj_assert(expr)
Runtime assertion macro.
Definition
assert.h:34
main
int main(int argc, char *argv[])
Definition
audio_pcm.c:177
bj_get_log_level
int bj_get_log_level(void)
Gets the current log level set by bj_set_log_level.
bj_info
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
Definition
log.h:141
bj_warn
#define bj_warn(...)
Log a message using the BJ_LOG_WARN level.
Definition
log.h:155
bj_err
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition
log.h:169
bj_set_log_level
void bj_set_log_level(int level)
Sets the default log level.
bj_log_msg
#define bj_log_msg(LEVEL,...)
Log a message using the given level LEVEL.
Definition
log.h:96
BJ_LOG_INFO
@ BJ_LOG_INFO
Informational messages about execution.
Definition
log.h:69
log.h
Logging utility functions.
main.h
Portable main() replacement with platform-aware entry shim.
examples
logging.c
Generated on
for Banjo API by
1.14.0