1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Use typedef for diagnostic levels, small refactor

This commit is contained in:
Broxzier
2017-01-04 23:51:50 +01:00
parent d857ebb2ad
commit a26eac91ef
3 changed files with 15 additions and 25 deletions

View File

@@ -163,7 +163,7 @@ exitcode_t CommandLine::HandleCommandDefault()
{
if (_verbose)
{
_log_levels[DIAGNOSTIC_LEVEL_VERBOSE] = 1;
_log_levels[DIAGNOSTIC_LEVEL_VERBOSE] = true;
PrintLaunchInformation();
}

View File

@@ -19,8 +19,8 @@
#include <stdio.h>
#include "diagnostic.h"
sint32 _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { 1, 1, 1, 0, 1 };
sint32 _log_location_enabled = 1;
static bool _log_location_enabled = true;
bool _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { true, true, true, false, true };
const char * _level_strings[] = {
"FATAL",
@@ -30,7 +30,7 @@ const char * _level_strings[] = {
"INFO"
};
void diagnostic_log(sint32 diagnosticLevel, const char *format, ...)
void diagnostic_log(DiagnosticLevel diagnosticLevel, const char *format, ...)
{
FILE *stream;
va_list args;
@@ -52,7 +52,7 @@ void diagnostic_log(sint32 diagnosticLevel, const char *format, ...)
fprintf(stream, "\n");
}
void diagnostic_log_with_location(sint32 diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...)
void diagnostic_log_with_location(DiagnosticLevel diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...)
{
FILE *stream;
va_list args;

View File

@@ -17,14 +17,16 @@
#ifndef _DIAGNOSTIC_H_
#define _DIAGNOSTIC_H_
enum {
#include "common.h"
typedef enum {
DIAGNOSTIC_LEVEL_FATAL,
DIAGNOSTIC_LEVEL_ERROR,
DIAGNOSTIC_LEVEL_WARNING,
DIAGNOSTIC_LEVEL_VERBOSE,
DIAGNOSTIC_LEVEL_INFORMATION,
DIAGNOSTIC_LEVEL_COUNT
};
} DiagnosticLevel;
/**
* Compile-time debug levels.
@@ -48,8 +50,6 @@ enum {
* only checking whether the define is present or not.
*/
#include "common.h"
#if defined(DEBUG)
#if DEBUG > 0
#define DEBUG_LEVEL_1 1
@@ -75,32 +75,24 @@ enum {
#define DEBUG_LEVEL_1 0
#endif // defined(DEBUG)
extern sint32 _log_levels[DIAGNOSTIC_LEVEL_COUNT];
extern bool _log_levels[DIAGNOSTIC_LEVEL_COUNT];
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void diagnostic_log(sint32 diagnosticLevel, const char *format, ...);
void diagnostic_log_with_location(sint32 diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...);
void diagnostic_log(DiagnosticLevel diagnosticLevel, const char *format, ...);
void diagnostic_log_with_location(DiagnosticLevel diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...);
#ifdef __cplusplus
}
#endif // __cplusplus
#ifdef _MSC_VER
#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__)
#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__)
#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, ## __VA_ARGS__)
#else
#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ## __VA_ARGS__)
#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ## __VA_ARGS__)
#endif // _MSC_VER
#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__)
@@ -109,5 +101,3 @@ void diagnostic_log_with_location(sint32 diagnosticLevel, const char *file, cons
#define log_info(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_INFORMATION, format, ## __VA_ARGS__)
#endif
#endif