2014-11-21 19:39:56 +01:00
|
|
|
/*****************************************************************************
|
2019-03-17 08:16:15 +01:00
|
|
|
* Copyright (c) 2014-2019 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
2014-11-21 19:39:56 +01:00
|
|
|
|
|
|
|
#ifndef _DIAGNOSTIC_H_
|
|
|
|
#define _DIAGNOSTIC_H_
|
|
|
|
|
2018-06-21 01:07:44 +02:00
|
|
|
#include <cstdint>
|
2017-01-04 23:51:50 +01:00
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
enum DIAGNOSTIC_LEVEL
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
DIAGNOSTIC_LEVEL_FATAL,
|
|
|
|
DIAGNOSTIC_LEVEL_ERROR,
|
|
|
|
DIAGNOSTIC_LEVEL_WARNING,
|
|
|
|
DIAGNOSTIC_LEVEL_VERBOSE,
|
|
|
|
DIAGNOSTIC_LEVEL_INFORMATION,
|
|
|
|
DIAGNOSTIC_LEVEL_COUNT
|
2018-02-14 09:42:26 +01:00
|
|
|
};
|
2014-11-21 19:39:56 +01:00
|
|
|
|
2015-12-11 16:38:37 +01:00
|
|
|
/**
|
2015-10-30 11:00:35 +01:00
|
|
|
* Compile-time debug levels.
|
|
|
|
*
|
|
|
|
* When compiling, just add -DDEBUG={0,1,2,3} (where 0 means disabled)
|
|
|
|
* Regardless of DEBUG value, a set of defines will be created:
|
|
|
|
* - DEBUG_LEVEL_1
|
|
|
|
* - DEBUG_LEVEL_2
|
|
|
|
* - DEBUG_LEVEL_3
|
|
|
|
* which you would use like so:
|
|
|
|
*
|
|
|
|
* #if DEBUG_LEVEL_1
|
|
|
|
* (... some debug code ...)
|
|
|
|
* #if DEBUG_LEVEL_2
|
|
|
|
* (... more debug code ...)
|
|
|
|
* #endif // DEBUG_LEVEL_2
|
|
|
|
* #endif // DEBUG_LEVEL_1
|
|
|
|
*
|
|
|
|
* The defines will be either 0 or 1 so compiler will complain about undefined
|
|
|
|
* macro if you forget to include the file, which would not happen if we were
|
|
|
|
* only checking whether the define is present or not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2018-07-21 16:17:06 +02:00
|
|
|
# if DEBUG > 0
|
|
|
|
# define DEBUG_LEVEL_1 1
|
|
|
|
# if DEBUG > 1
|
|
|
|
# define DEBUG_LEVEL_2 1
|
|
|
|
# if DEBUG > 2
|
|
|
|
# define DEBUG_LEVEL_3 1
|
|
|
|
# else
|
|
|
|
# define DEBUG_LEVEL_3 0
|
|
|
|
# endif // DEBUG > 2
|
|
|
|
# else
|
|
|
|
# define DEBUG_LEVEL_3 0
|
|
|
|
# define DEBUG_LEVEL_2 0
|
|
|
|
# endif // DEBUG > 1
|
|
|
|
# else
|
|
|
|
# define DEBUG_LEVEL_1 0
|
|
|
|
# define DEBUG_LEVEL_2 0
|
|
|
|
# define DEBUG_LEVEL_3 0
|
|
|
|
# endif // DEBUG > 0
|
2015-10-30 11:00:35 +01:00
|
|
|
#else
|
2018-07-21 16:17:06 +02:00
|
|
|
# define DEBUG_LEVEL_3 0
|
|
|
|
# define DEBUG_LEVEL_2 0
|
|
|
|
# define DEBUG_LEVEL_1 0
|
2015-10-30 11:00:35 +01:00
|
|
|
#endif // defined(DEBUG)
|
|
|
|
|
2017-09-18 17:05:28 +02:00
|
|
|
extern bool _log_levels[DIAGNOSTIC_LEVEL_COUNT];
|
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char* format, ...);
|
|
|
|
void diagnostic_log_with_location(
|
|
|
|
DIAGNOSTIC_LEVEL diagnosticLevel, const char* file, const char* function, int32_t line, const char* format, ...);
|
2014-11-21 19:39:56 +01:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2018-07-21 16:17:06 +02:00
|
|
|
# define diagnostic_log_macro(level, format, ...) \
|
|
|
|
diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
|
2014-11-21 19:39:56 +01:00
|
|
|
#else
|
2018-07-21 16:17:06 +02:00
|
|
|
# define diagnostic_log_macro(level, format, ...) \
|
|
|
|
diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ##__VA_ARGS__)
|
2017-01-04 23:51:50 +01:00
|
|
|
#endif // _MSC_VER
|
2014-11-21 20:32:13 +01:00
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
#define log_fatal(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_FATAL, format, ##__VA_ARGS__)
|
|
|
|
#define log_error(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_ERROR, format, ##__VA_ARGS__)
|
|
|
|
#define log_warning(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_WARNING, format, ##__VA_ARGS__)
|
|
|
|
#define log_verbose(format, ...) diagnostic_log(DIAGNOSTIC_LEVEL_VERBOSE, format, ##__VA_ARGS__)
|
|
|
|
#define log_info(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_INFORMATION, format, ##__VA_ARGS__)
|
2014-11-21 20:32:13 +01:00
|
|
|
|
2014-11-21 19:39:56 +01:00
|
|
|
#endif
|