//////////////////////////////////////////////////////////// //~ Log event types Struct(LogEvent) { u64 id; u64 level_id; DateTime datetime; i64 time_ns; String msg; i32 level; i32 thread_id; i32 fiber_id; }; Struct(LogEventsArray) { u64 count; LogEvent *logs; }; //////////////////////////////////////////////////////////// //~ Logging levels #define LogLevel(l) (l <= LogLevel_CompTime) /* Log level configuration */ #ifndef LogLevel_CompTime # if RtcIsEnabled || ProfilingIsEnabled # define LogLevel_CompTime LogLevel_Debug # else # define LogLevel_CompTime LogLevel_Info # endif #endif #define LogLevel_None -1 #define LogLevel_Critical 0 #define LogLevel_Error 1 #define LogLevel_Warning 2 #define LogLevel_Success 3 #define LogLevel_Info 4 #define LogLevel_Debug 5 #define LogLevel_Count 6 //////////////////////////////////////////////////////////// //~ Log level types Struct(LogLevelSettings) { String shorthand; }; Global Readonly LogLevelSettings log_settings[LogLevel_Count] = { [LogLevel_Critical] = { CompLit("CRITICAL"), }, [LogLevel_Error] = { CompLit("ERROR"), }, [LogLevel_Warning] = { CompLit("WARNING"), }, [LogLevel_Success] = { CompLit("SUCCESS"), }, [LogLevel_Info] = { CompLit("INFO"), }, [LogLevel_Debug] = { CompLit("DEBUG"), } }; //////////////////////////////////////////////////////////// //~ Compile-time logging macros #if LogLevel(LogLevel_Critical) # define LogCritical(msg) Log_(LogLevel_Critical, msg) # define LogCriticalF(fmt_lit, ...) LogF_(LogLevel_Critical, Lit(fmt_lit) , ## __VA_ARGS__, FmtEnd) #else # define LogCritical(msg) # define LogCriticalF(...) #endif #if LogLevel(LogLevel_Error) # define LogError(msg) Log_(LogLevel_Error, msg) # define LogErrorF(fmt_lit, ...) LogF_(LogLevel_Error, Lit(fmt_lit) , ## __VA_ARGS__, FmtEnd) #else # define LogError(msg) # define LogErrorF(...) #endif #if LogLevel(LogLevel_Warning) # define LogWarning(msg) Log_(LogLevel_Warning, msg) # define LogWarningF(fmt_lit, ...) LogF_(LogLevel_Warning, Lit(fmt_lit) , ## __VA_ARGS__, FmtEnd) #else # define LogWarning(msg) # define LogWarningF(...) #endif #if LogLevel(LogLevel_Success) # define LogSuccess(msg) Log_(LogLevel_Success, msg) # define LogSuccessF(fmt_lit, ...) LogF_(LogLevel_Success, Lit(fmt_lit) , ## __VA_ARGS__, FmtEnd) #else # define LogSuccess(msg) # define LogSuccessF(...) #endif #if LogLevel(LogLevel_Info) # define LogInfo(msg) Log_(LogLevel_Info, msg) # define LogInfoF(fmt_lit, ...) LogF_(LogLevel_Info, Lit(fmt_lit) , ## __VA_ARGS__, FmtEnd) #else # define LogInfo(msg) # define LogInfoF(...) #endif #if LogLevel(LogLevel_Debug) # define LogDebug(msg) Log_(LogLevel_Debug, msg) # define LogDebugF(fmt_lit, ...) LogF_(LogLevel_Debug, Lit(fmt_lit) , ## __VA_ARGS__, FmtEnd) #else # define LogDebug(msg) # define LogDebugF(...) #endif //////////////////////////////////////////////////////////// //~ @hookdecl Init hooks void InitLogSystem(String logfile_path); //////////////////////////////////////////////////////////// //~ @hookdecl Log hooks /* NOTE: Calling these functions rather than using the logging macros may result in logs that are compiled regardless of log level. */ void LogPanic(String msg); void Log_(i32 level, String msg); void LogF_(i32 level, String fmt, ...); LogEventsArray GetLogEvents(void);