Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
Log.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_LOG_H
22 #define GF_LOG_H
23 
24 #include <cstdarg>
25 #include <cstdlib>
26 #include <map>
27 
28 #include "CoreApi.h"
29 #include "Portability.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
60  class GF_CORE_API Log {
61  public:
65  Log() = delete;
66 
70  enum Level : int {
72  Info,
73  Warn,
76  };
77 
83  static void setLevel(Level level);
84 
90  static void debug(const char *fmt, ...) GF_FORMAT(1, 2) {
91  va_list ap;
92  va_start(ap, fmt);
93  log(Level::Debug, fmt, ap);
94  va_end(ap);
95  }
96 
102  static void info(const char *fmt, ...) GF_FORMAT(1, 2) {
103  va_list ap;
104  va_start(ap, fmt);
105  log(Level::Info, fmt, ap);
106  va_end(ap);
107  }
108 
114  static void warning(const char *fmt, ...) GF_FORMAT(1, 2) {
115  va_list ap;
116  va_start(ap, fmt);
117  log(Level::Warn, fmt, ap);
118  va_end(ap);
119  }
120 
126  static void error(const char *fmt, ...) GF_FORMAT(1, 2) {
127  va_list ap;
128  va_start(ap, fmt);
129  log(Level::Error, fmt, ap);
130  va_end(ap);
131  }
132 
138  static void fatal(const char *fmt, ...) GF_FORMAT(1, 2) {
139  va_list ap;
140  va_start(ap, fmt);
141  log(Level::Fatal, fmt, ap);
142  va_end(ap);
143 
144  std::abort();
145  }
146 
147  private:
148  static Level s_level;
149 
150  private:
151  static void log(Level level, const char *fmt, va_list ap);
152  };
153 
154 #ifndef DOXYGEN_SHOULD_SKIP_THIS
155 }
156 #endif
157 }
158 
159 #endif // GF_LOG_H
The fatal level.
Definition: Log.h:75
Level
The severity level of the log.
Definition: Log.h:70
static void error(const char *fmt,...)
Print an error message.
Definition: Log.h:126
The warn level.
Definition: Log.h:73
static void fatal(const char *fmt,...)
Print a fatal message and quit.
Definition: Log.h:138
The debug level.
Definition: Log.h:71
static void warning(const char *fmt,...)
Print a warning message.
Definition: Log.h:114
An error occurred.
The namespace for gf classes.
Definition: Action.h:35
static void info(const char *fmt,...)
Print an info message.
Definition: Log.h:102
Logging functions.
Definition: Log.h:60
static void debug(const char *fmt,...)
Print a debug message.
Definition: Log.h:90
The error level.
Definition: Log.h:74
The info level.
Definition: Log.h:72