Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
log.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L))
9#if defined(__has_include)
10#if __has_include(<source_location>)
11#include <source_location>
12#if defined(__cpp_lib_source_location) && (__cpp_lib_source_location >= 201907L)
13#define FLECS_CPP_SOURCE_LOCATION
14#endif
15#endif
16#endif
17#endif
18
19namespace flecs {
20namespace log {
21
22namespace _ {
23
24struct fmt_str {
25#ifdef FLECS_CPP_SOURCE_LOCATION
26 fmt_str(const char *fmt_,
27 std::source_location loc = std::source_location::current())
28 : fmt(fmt_)
29 , file(loc.file_name())
30 , line(static_cast<int32_t>(loc.line())) { }
31#else
32 fmt_str(const char *fmt_)
33 : fmt(fmt_)
34 , file(__FILE__)
35 , line(__LINE__) { }
36#endif
37
38 const char *fmt;
39 const char *file;
40 int32_t line;
41};
42
43}
44
57inline void set_level(int level) {
58 ecs_log_set_level(level);
59}
60
65inline int get_level() {
66 return ecs_log_get_level();
67}
68
73inline void enable_colors(bool enabled = true) {
74 ecs_log_enable_colors(enabled);
75}
76
81inline void enable_timestamp(bool enabled = true) {
83}
84
89inline void enable_timedelta(bool enabled = true) {
91}
92
97inline void dbg(_::fmt_str fmt, ...) {
98 va_list args;
99 va_start(args, fmt);
100 ecs_logv_(1, fmt.file, fmt.line, fmt.fmt, args);
101 va_end(args);
102}
103
108inline void trace(_::fmt_str fmt, ...) {
109 va_list args;
110 va_start(args, fmt);
111 ecs_logv_(0, fmt.file, fmt.line, fmt.fmt, args);
112 va_end(args);
113}
114
119inline void warn(_::fmt_str fmt, ...) {
120 va_list args;
121 va_start(args, fmt);
122 ecs_logv_(-2, fmt.file, fmt.line, fmt.fmt, args);
123 va_end(args);
124}
125
130inline void err(_::fmt_str fmt, ...) {
131 va_list args;
132 va_start(args, fmt);
133 ecs_logv_(-3, fmt.file, fmt.line, fmt.fmt, args);
134 va_end(args);
135}
136
141inline void push(_::fmt_str fmt, ...) {
142 va_list args;
143 va_start(args, fmt);
144 ecs_logv_(0, fmt.file, fmt.line, fmt.fmt, args);
145 va_end(args);
146 ecs_log_push();
147}
148
150inline void push() {
151 ecs_log_push();
152}
153
155inline void pop() {
156 ecs_log_pop();
157}
158
161}
162}
FLECS_API void ecs_logv_(int32_t level, const char *file, int32_t line, const char *fmt, va_list args)
Log at the provided level (va_list).
#define ecs_log_push()
Push log indentation at the default level.
Definition log.h:458
FLECS_API bool ecs_log_enable_colors(bool enabled)
Enable/disable tracing with colors.
FLECS_API int ecs_log_get_level(void)
Get current log level.
#define ecs_log_pop()
Pop log indentation at the default level.
Definition log.h:460
FLECS_API int ecs_log_set_level(int level)
Enable or disable log.
FLECS_API bool ecs_log_enable_timestamp(bool enabled)
Enable/disable logging timestamp.
FLECS_API bool ecs_log_enable_timedelta(bool enabled)
Enable/disable logging time since last log.
void enable_colors(bool enabled=true)
Enable colors in logging.
Definition log.hpp:73
void enable_timedelta(bool enabled=true)
Enable time delta in logging.
Definition log.hpp:89
void push()
Increase log indentation.
Definition log.hpp:150
void set_level(int level)
Set the log level.
Definition log.hpp:57
void warn(_::fmt_str fmt,...)
Warning (level -2).
Definition log.hpp:119
void dbg(_::fmt_str fmt,...)
Debug trace (level 1).
Definition log.hpp:97
int get_level()
Get the log level.
Definition log.hpp:65
void trace(_::fmt_str fmt,...)
Trace (level 0).
Definition log.hpp:108
void pop()
Decrease log indentation.
Definition log.hpp:155
void enable_timestamp(bool enabled=true)
Enable timestamps in logging.
Definition log.hpp:81
void err(_::fmt_str fmt,...)
Error (level -3).
Definition log.hpp:130