cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
main.c
1#include <stdio.h>
2#include "base/base_macros.h"
3#include "base/base_types.h"
4#include "base/base_strings.h"
5#include "base/base_log.h"
6#include "memory/mem_arena.h"
7
8int main(void) {
9 // Basic colored logging
10 LOG_INFO("Application started successfully.");
11 LOG_DEBUG("Memory arena initialized with %d MB.", 512);
12
13 // Test sized strings with logging!
14 String8 file_name = STR8("config.ini");
15 LOG_WARN("Configuration file '%.*s' not found, using defaults.", STR8_FMT(file_name));
16
17 // Add a file sink and test it
18 FILE *log_file = fopen("app.log", "a");
19 if (log_file) {
20 log_add_fp(log_file, LOG_LEVEL_TRACE); // Write ALL logs to the file
21 LOG_INFO("This message will go to both the console AND the file!");
22 fclose(log_file); // Remember to close in real code!
23 }
24
25 return 0;
26}
Professional, thread-safe, leveled logging system.
#define LOG_INFO(...)
Logs an INFO level message (General application flow).
Definition base_log.h:122
#define LOG_DEBUG(...)
Logs a DEBUG level message (Diagnostic info).
Definition base_log.h:120
#define LOG_WARN(...)
Logs a WARN level message (Abnormal but non-fatal).
Definition base_log.h:124
Context detection, utilities, compiler abstractions, and data structures.
Sized string (string slice) definitions and helper macros.
Core type definitions and fixed-width aliases.
b32 log_add_fp(FILE *fp, LogLevel min_level)
Adds a standard C FILE* pointer as a logging destination.
Definition base_log.c:160
@ LOG_LEVEL_TRACE
Definition base_log.h:43
#define STR8_FMT(s)
Helper macro to use a String8 in a printf-style format string. Example:
#define STR8(s)
Wraps a C string literal into a String8 struct at compile time.
High-performance Virtual Memory Linear (Arena) Allocator.
A sized UTF-8 string slice.