SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
sbgl_internal_log.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
Include dependency graph for sbgl_internal_log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sbgl_LogConfig
 Logging configuration. More...
 

Macros

#define sbgl_log_impl(level, category, msg)
 

Enumerations

enum  sbgl_LogLevel {
  SBGL_LOG_DEBUG = 0 , SBGL_LOG_INFO = 1 , SBGL_LOG_WARN = 2 , SBGL_LOG_ERROR = 3 ,
  SBGL_LOG_CRITICAL = 4
}
 Logging severity levels. More...
 
enum  sbgl_LogCategory {
  SBGL_LOG_CAT_CORE = 0 , SBGL_LOG_CAT_PLATFORM = 1 , SBGL_LOG_CAT_GFX = 2 , SBGL_LOG_CAT_INPUT = 3 ,
  SBGL_LOG_CAT_VOXEL = 4 , SBGL_LOG_CAT_COUNT = 5
}
 Logging categories for component filtering. More...
 

Functions

void sbgl_internal_log_impl (sbgl_LogLevel level, sbgl_LogCategory category, const char *file, int line, const char *function, const char *message)
 
void sbgl_LogSetLevel (sbgl_LogLevel minLevel)
 
void sbgl_LogSetOutput (const char *path)
 
void sbgl_LogSetFileRotation (uint32_t maxFiles, size_t maxSize)
 
const char * sbgl_ResultToString (int result)
 
const char * sbgl_VkResultToString (int32_t vkResult)
 

Macro Definition Documentation

◆ sbgl_log_impl

#define sbgl_log_impl ( level,
category,
msg )
Value:
sbgl_internal_log_impl(level, category, __FILE__, __LINE__, __func__, msg)
void sbgl_internal_log_impl(sbgl_LogLevel level, sbgl_LogCategory category, const char *file, int line, const char *function, const char *message)
Definition sbgl_log.c:116

Definition at line 52 of file sbgl_internal_log.h.

52#define sbgl_log_impl(level, category, msg) \
53 sbgl_internal_log_impl(level, category, __FILE__, __LINE__, __func__, msg)

Enumeration Type Documentation

◆ sbgl_LogCategory

Logging categories for component filtering.

Enumerator
SBGL_LOG_CAT_CORE 
SBGL_LOG_CAT_PLATFORM 
SBGL_LOG_CAT_GFX 
SBGL_LOG_CAT_INPUT 
SBGL_LOG_CAT_VOXEL 
SBGL_LOG_CAT_COUNT 

Definition at line 22 of file sbgl_internal_log.h.

22 {
sbgl_LogCategory
Logging categories for component filtering.
@ SBGL_LOG_CAT_PLATFORM
@ SBGL_LOG_CAT_INPUT
@ SBGL_LOG_CAT_COUNT
@ SBGL_LOG_CAT_GFX
@ SBGL_LOG_CAT_CORE
@ SBGL_LOG_CAT_VOXEL

◆ sbgl_LogLevel

Logging severity levels.

Enumerator
SBGL_LOG_DEBUG 
SBGL_LOG_INFO 
SBGL_LOG_WARN 
SBGL_LOG_ERROR 
SBGL_LOG_CRITICAL 

Definition at line 11 of file sbgl_internal_log.h.

11 {
13 SBGL_LOG_INFO = 1,
14 SBGL_LOG_WARN = 2,
sbgl_LogLevel
Logging severity levels.
@ SBGL_LOG_CRITICAL
@ SBGL_LOG_WARN
@ SBGL_LOG_ERROR
@ SBGL_LOG_INFO
@ SBGL_LOG_DEBUG

Function Documentation

◆ sbgl_internal_log_impl()

void sbgl_internal_log_impl ( sbgl_LogLevel level,
sbgl_LogCategory category,
const char * file,
int line,
const char * function,
const char * message )

Definition at line 116 of file sbgl_log.c.

123 {
124 if (level < s_config.minLevel) return;
125 if (!((1u << category) & s_config.categoryMask)) return;
126
127 time_t now = time(NULL);
128 struct tm* tm_info = localtime(&now);
129 char time_buf[32];
130 strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", tm_info);
131
132 char out[1024];
133 int len = snprintf(out, sizeof(out), "[%s] [%s] [%s] %s:%d (%s): %s\n",
134 time_buf,
135 level_strings[level],
136 category_strings[category],
137 file,
138 line,
139 function,
140 message
141 );
142
143 if (len < 0) return;
144
145 if (s_config.fileEnabled) {
146 if (!s_file) {
148 }
149
150 if (s_file) {
151 if (ftell(s_file) > (long)s_config.maxFileSize) {
152 rotate_logs();
154 }
155
156 if (s_file) {
157 fwrite(out, 1, len, s_file);
158 fflush(s_file);
159 }
160 }
161 }
162
163 FILE* dst = (level >= SBGL_LOG_ERROR) ? stderr : stdout;
164 fwrite(out, 1, len, dst);
165}
static const char * level_strings[]
Definition sbgl_log.c:68
static void open_log_file(void)
Definition sbgl_log.c:105
static sbgl_LogConfig s_config
Definition sbgl_log.c:8
static void rotate_logs(void)
Definition sbgl_log.c:84
static FILE * s_file
Definition sbgl_log.c:17
static const char * category_strings[]
Definition sbgl_log.c:76
sbgl_LogLevel minLevel

◆ sbgl_LogSetFileRotation()

void sbgl_LogSetFileRotation ( uint32_t maxFiles,
size_t maxSize )

Definition at line 186 of file sbgl_log.c.

186 {
187 s_config.maxFiles = maxFiles;
188 s_config.maxFileSize = maxFileSize;
189}

◆ sbgl_LogSetLevel()

void sbgl_LogSetLevel ( sbgl_LogLevel minLevel)

Definition at line 167 of file sbgl_log.c.

167 {
168 s_config.minLevel = minLevel;
169}

◆ sbgl_LogSetOutput()

void sbgl_LogSetOutput ( const char * path)

Definition at line 171 of file sbgl_log.c.

171 {
172 if (!path) {
173 s_config.fileEnabled = false;
174 if (s_file) {
175 fclose(s_file);
176 s_file = NULL;
177 }
178 return;
179 }
180
181 s_config.fileEnabled = true;
182 s_config.filePath = path;
184}
const char * filePath

◆ sbgl_ResultToString()

const char * sbgl_ResultToString ( int result)

Definition at line 191 of file sbgl_log.c.

191 {
192 if (result >= 0 && result < (int)(sizeof(SBGL_RESULT_STRINGS) / sizeof(SBGL_RESULT_STRINGS[0]))) {
193 return SBGL_RESULT_STRINGS[result];
194 }
195 return "SBGL_UNKNOWN_ERROR";
196}
static const char *const SBGL_RESULT_STRINGS[]
Definition sbgl_log.c:19

◆ sbgl_VkResultToString()

const char * sbgl_VkResultToString ( int32_t vkResult)

Definition at line 198 of file sbgl_log.c.

198 {
199 for (int i = 0; i < VK_RESULT_COUNT; i++) {
200 if (VK_RESULT_CODES[i] == vkResult) {
201 return VK_RESULT_STRINGS[i];
202 }
203 }
204 return "VK_UNKNOWN";
205}
static const char *const VK_RESULT_STRINGS[]
Definition sbgl_log.c:42
static const int32_t VK_RESULT_CODES[]
Definition sbgl_log.c:36
#define VK_RESULT_COUNT
Definition sbgl_log.c:35