Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Log.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 "Portability.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
59  class GF_API Log {
60  public:
64  Log() = delete;
65 
69  enum Level : int {
71  Info,
72  Warn,
75  };
76 
82  static void setLevel(Level level);
83 
89  static void debug(const char *fmt, ...) GF_FORMAT(1, 2) {
90  va_list ap;
91  va_start(ap, fmt);
92  log(Level::Debug, fmt, ap);
93  va_end(ap);
94  }
95 
101  static void info(const char *fmt, ...) GF_FORMAT(1, 2) {
102  va_list ap;
103  va_start(ap, fmt);
104  log(Level::Info, fmt, ap);
105  va_end(ap);
106  }
107 
113  static void warning(const char *fmt, ...) GF_FORMAT(1, 2) {
114  va_list ap;
115  va_start(ap, fmt);
116  log(Level::Warn, fmt, ap);
117  va_end(ap);
118  }
119 
125  static void error(const char *fmt, ...) GF_FORMAT(1, 2) {
126  va_list ap;
127  va_start(ap, fmt);
128  log(Level::Error, fmt, ap);
129  va_end(ap);
130  }
131 
137  static void fatal(const char *fmt, ...) GF_FORMAT(1, 2) {
138  va_list ap;
139  va_start(ap, fmt);
140  log(Level::Fatal, fmt, ap);
141  va_end(ap);
142 
143  std::abort();
144  }
145 
146  private:
147  static Level s_level;
148 
149  private:
150  static void log(Level level, const char *fmt, va_list ap);
151  };
152 
153 #ifndef DOXYGEN_SHOULD_SKIP_THIS
154 }
155 #endif
156 }
157 
158 #endif // GF_LOG_H
The fatal level.
Definition: Log.h:74
Level
The severity level of the log.
Definition: Log.h:69
static void error(const char *fmt,...)
Print an error message.
Definition: Log.h:125
The warn level.
Definition: Log.h:72
static void fatal(const char *fmt,...)
Print a fatal message and quit.
Definition: Log.h:137
The debug level.
Definition: Log.h:70
static void warning(const char *fmt,...)
Print a warning message.
Definition: Log.h:113
The namespace for gf classes.
Definition: Action.h:35
static void info(const char *fmt,...)
Print an info message.
Definition: Log.h:101
Logging functions.
Definition: Log.h:59
static void debug(const char *fmt,...)
Print a debug message.
Definition: Log.h:89
The error level.
Definition: Log.h:73
The info level.
Definition: Log.h:71