Fireset
Loading...
Searching...
No Matches
fslog.h
1// Copyright (c) 2025-2026 Henrique Rodrigues Santos
2// Licensed under the MIT License
3// Github: https://github.com/saintsHr/Fireset
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <stdarg.h>
8
9#include "fireset/fstime.h"
10
11static double s_log_start_time = 0.0;
12
13typedef enum{
14 FS_INFO,
15 FS_WARNING,
16 FS_ERROR,
17 FS_FATAL,
18
19 FS_SEV_COUNT
20}FS_SEVERITY;
21
22typedef enum{
23 FS_AUDIO,
24 FS_CORE,
25 FS_TIME,
26 FS_ASSETS,
27 FS_INPUT,
28 FS_RENDER,
29 FS_WINDOW,
30 FS_PHYSICS,
31
32 FS_MOD_COUNT
33}FS_MODULE;
34
35static const char* FS_ERROR_STRING[FS_SEV_COUNT] = {
36 "INFO",
37 "WARNING",
38 "ERROR",
39 "FATAL"
40};
41
42static const char* FS_MODULE_STRING[FS_MOD_COUNT] = {
43 "Audio",
44 "Core",
45 "Time",
46 "Assets",
47 "Input",
48 "Render",
49 "Window",
50 "Physics"
51};
52
53static const char* FS_ERROR_COLOR[FS_SEV_COUNT] = {
54 "\033[96m",
55 "\033[95m",
56 "\033[91m",
57 "\033[31m"
58};
59
60static inline void fsLogInit(void){
61 s_log_start_time = fsTimeGetSystemTime();
62}
63
64static inline void fsLog(FS_SEVERITY sev, FS_MODULE mod, const char* fmt, ...){
65 if (sev < 0 || sev >= FS_SEV_COUNT) return;
66 if (mod < 0 || mod >= FS_MOD_COUNT) return;
67
68 double time = fsTimeGetTime();
69
70 unsigned long long totalMs = (unsigned long long)(time * 1000.0);
71
72 unsigned long long ms = totalMs % 1000;
73 unsigned long long totalSeconds = totalMs / 1000;
74
75 unsigned long long s = totalSeconds % 60;
76 unsigned long long m = (totalSeconds / 60) % 60;
77 unsigned long long h = totalSeconds / 3600;
78
79 printf(
80 "[%02lld:%02lld:%02lld.%03lld][%s%s\033[0m][%s] ",
81 h, m, s, ms,
82 FS_ERROR_COLOR[sev],
83 FS_ERROR_STRING[sev],
84 FS_MODULE_STRING[mod]
85 );
86
87 va_list args;
88 va_start(args, fmt);
89 vprintf(fmt, args);
90 va_end(args);
91
92 printf("\n");
93 fflush(stdout);
94
95 if (sev == FS_FATAL) exit(EXIT_FAILURE);
96}
double fsTimeGetSystemTime(void)
Returns the current system time.
double fsTimeGetTime(void)
Returns the engine running time.
Definition fstime.c:72