| 1 | // LAF Base Library |
| 2 | // Copyright (c) 2020 Igara Studio S.A. |
| 3 | // Copyright (c) 2001-2017 David Capello |
| 4 | // |
| 5 | // This file is released under the terms of the MIT license. |
| 6 | // Read LICENSE.txt for more information. |
| 7 | |
| 8 | // Always undefine ERROR macro just in case (so we can include |
| 9 | // base/log.h as the last header file) |
| 10 | #ifdef ERROR |
| 11 | #undef ERROR |
| 12 | #endif |
| 13 | |
| 14 | #ifndef BASE_LOG_H_INCLUDED |
| 15 | #define BASE_LOG_H_INCLUDED |
| 16 | |
| 17 | // Don't use pragma once because we want to undef ERROR each time this |
| 18 | // file is included. |
| 19 | //#pragma once |
| 20 | |
| 21 | enum LogLevel { |
| 22 | NONE = 0, // Default log level: do not log |
| 23 | FATAL = 1, // Something failed and we CANNOT continue the execution |
| 24 | ERROR = 2, // Something failed, the UI should show this, and we can continue |
| 25 | WARNING = 3, // Something failed, the UI don't need to show this, and we can continue |
| 26 | INFO = 4, // Information about some important event |
| 27 | VERBOSE = 5, // Information step by step |
| 28 | }; |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | #include <iosfwd> |
| 32 | |
| 33 | namespace base { |
| 34 | |
| 35 | void set_log_filename(const char* filename); |
| 36 | void set_log_level(const LogLevel level); |
| 37 | LogLevel get_log_level(); |
| 38 | |
| 39 | } // namespace base |
| 40 | |
| 41 | // E.g. LOG("text in information log level\n"); |
| 42 | void LOG(const char* format, ...); |
| 43 | void LOG(const LogLevel level, const char* format, ...); |
| 44 | |
| 45 | inline void LOG(int) { |
| 46 | // This is in case LOG() is used with an integer value instead of |
| 47 | // LogLevel, an error must be triggered (e.g. on wingdi.h ERROR is |
| 48 | // defined as 0, and with this definition we avoid calling LOG(const |
| 49 | // char* format=0=nullptr) and we detect the problem at compile |
| 50 | // time. |
| 51 | } |
| 52 | |
| 53 | #endif |
| 54 | |
| 55 | #endif |
| 56 | |