CG_Labs
2020.0
src
core
Log.h
Go to the documentation of this file.
1
/*
2
* Error and warning handling system
3
*/
4
5
#include "
BuildSettings.h
"
6
7
#include <cstddef>
8
#include <cstdarg>
9
10
#pragma once
11
//#define ENABLE_ASSERT 1
12
//#define ENABLE_PARAM_CHECK 1
13
14
#define SUCCESS(r) ((r) == RESULT_SUCCESS)
15
#define FAILURE(r) (!SUCCESS(r))
16
17
#if defined ENABLE_ASSERT && ENABLE_ASSERT != 0
18
# define Assert(m) if (!(static_cast<unsigned int>(m))) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_ASSERT, "Assertion failed at line %u in file %s.", __LINE__, __FILE__)
19
#else
20
# define Assert(a)
21
#endif
22
23
#if defined ENABLE_PARAM_CHECK && ENABLE_PARAM_CHECK != 0
24
# define Param(m) Log::ReportParam(static_cast<unsigned int>(m), __FILE__, __FUNCTION__, __LINE__)
25
#else
26
# define Param(a) true
27
#endif
28
29
#define LOG_MESSAGE_ONCE_FLAG 1
30
#define LOG_LOCATION_ONCE_FLAG 2
31
32
namespace
Log
{
33
34
enum
Type
{
35
TYPE_SUCCESS
= 0,
36
TYPE_INFO
= 1,
37
TYPE_NEUTRAL
= 2,
38
TYPE_WARNING
= 3,
39
TYPE_ERROR
= 4,
40
TYPE_FILE
= 5,
41
TYPE_ASSERT
= 6,
42
TYPE_PARAM
= 7,
43
TYPE_TRIVIA
= 8,
44
N_TYPES
= 9
45
};
46
47
enum
Severity
{
48
OK
= 0,
49
BAD
,
50
TERMINAL
51
};
52
enum
Verbosity
{
53
WHISPER
= 0,
// Disregard message
54
LOUD_UNSITUATED
,
// Display message
55
LOUD
// Display message, with file, function and line prepended
56
};
57
58
#define LOG_OUT_STD (1 << 0)
59
#define LOG_OUT_FILE (1 << 1)
60
#define LOG_OUT_CUSTOM (1 << 15)
61
62
void
Init
();
63
void
Destroy
();
64
void
SetCustomOutputTargetFunc
(
void
(* textout)(
Type
,
const
char
*));
65
void
SetOutputTargets
(std::size_t targets);
66
void
SetVerbosity
(
Type
type,
Verbosity
verbosity);
67
void
SetIncludeThreadID
(
bool
inc);
68
70
void
Report
(
71
unsigned
int
flags,
72
const
char
*file,
73
const
char
*
function
,
74
int
line,
75
Type
type,
76
const
char
*str,
77
...
78
);
79
80
bool
ReportParam
(
81
unsigned
int
test,
82
const
char
*file,
83
const
char
*
function
,
84
int
line
85
);
86
87
};
88
89
//__forceinline Log::Type operator|(Log::Type l, Log::Type r)
90
//{
91
// return static_cast<Log::Type>(static_cast<int>(l) | static_cast<int>(r));
92
//}
93
94
#if defined _WIN32
95
# define Log(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_NEUTRAL, static_cast<char const*>(m), __VA_ARGS__)
96
# define LogType(t, m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, t, static_cast<char const*>(m), __VA_ARGS__)
97
# define LogMsgOnce(t, m, ...) Log::Report(LOG_MESSAGE_ONCE_FLAG, __FILE__, __FUNCTION__, __LINE__, t, static_cast<char const*>(m), __VA_ARGS__)
98
# define LogLocOnce(t, m, ...) Log::Report(LOG_LOCATION_ONCE_FLAG, __FILE__, __FUNCTION__, __LINE__, t, static_cast<char const*>(m), __VA_ARGS__)
99
# define LogWarning(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_WARNING, static_cast<char const*>(m), __VA_ARGS__)
100
# define LogError(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_ERROR, static_cast<char const*>(m), __VA_ARGS__)
101
# define LogFile(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_FILE, static_cast<char const*>(m), __VA_ARGS__)
102
# define LogInfo(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_INFO, static_cast<char const*>(m), __VA_ARGS__)
103
# define LogTrivia(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_TRIVIA, static_cast<char const*>(m), __VA_ARGS__)
104
#else
105
# define Log(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_NEUTRAL, static_cast<char const*>(m), ##__VA_ARGS__)
106
# define LogType(t, m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, t, static_cast<char const*>(m), ##__VA_ARGS__)
107
# define LogMsgOnce(t, m, ...) Log::Report(LOG_MESSAGE_ONCE_FLAG, __FILE__, __FUNCTION__, __LINE__, t, static_cast<char const*>(m), ##__VA_ARGS__)
108
# define LogLocOnce(t, m, ...) Log::Report(LOG_LOCATION_ONCE_FLAG, __FILE__, __FUNCTION__, __LINE__, t, static_cast<char const*>(m), ##__VA_ARGS__)
109
# define LogWarning(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_WARNING, static_cast<char const*>(m), ##__VA_ARGS__)
110
# define LogError(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_ERROR, static_cast<char const*>(m), ##__VA_ARGS__)
111
# define LogFile(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_FILE, static_cast<char const*>(m), ##__VA_ARGS__)
112
# define LogInfo(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_INFO, static_cast<char const*>(m), ##__VA_ARGS__)
113
# define LogTrivia(m, ...) Log::Report(0, __FILE__, __FUNCTION__, __LINE__, Log::Type::TYPE_TRIVIA, static_cast<char const*>(m), ##__VA_ARGS__)
114
#endif
Log::SetIncludeThreadID
void SetIncludeThreadID(bool inc)
Definition:
Log.cpp:99
Log::TYPE_SUCCESS
@ TYPE_SUCCESS
Definition:
Log.h:35
Log::WHISPER
@ WHISPER
Definition:
Log.h:53
Log::LOUD_UNSITUATED
@ LOUD_UNSITUATED
Definition:
Log.h:54
Log::TYPE_WARNING
@ TYPE_WARNING
Definition:
Log.h:38
Log::OK
@ OK
Definition:
Log.h:48
Log::Type
Type
Definition:
Log.h:34
Log::Destroy
void Destroy()
Definition:
Log.cpp:54
Log::BAD
@ BAD
Definition:
Log.h:49
Log::N_TYPES
@ N_TYPES
Definition:
Log.h:44
Log::ReportParam
bool ReportParam(unsigned int test, const char *file, const char *function, int line)
Definition:
Log.cpp:184
Log::TYPE_INFO
@ TYPE_INFO
Definition:
Log.h:36
Log
Definition:
Log.cpp:14
Log::TYPE_NEUTRAL
@ TYPE_NEUTRAL
Definition:
Log.h:37
Log::SetCustomOutputTargetFunc
void SetCustomOutputTargetFunc(void(*textout)(Type, const char *))
Definition:
Log.cpp:68
BuildSettings.h
Log::Init
void Init()
Definition:
Log.cpp:47
Log::TYPE_ASSERT
@ TYPE_ASSERT
Definition:
Log.h:41
Log::SetOutputTargets
void SetOutputTargets(size_t flags)
Definition:
Log.cpp:75
Log::TYPE_FILE
@ TYPE_FILE
Definition:
Log.h:40
Log::SetVerbosity
void SetVerbosity(Type type, Verbosity verbosity)
Definition:
Log.cpp:92
Log::TYPE_TRIVIA
@ TYPE_TRIVIA
Definition:
Log.h:43
Log::TYPE_PARAM
@ TYPE_PARAM
Definition:
Log.h:42
Log::LOUD
@ LOUD
Definition:
Log.h:55
Log::Report
void Report(unsigned int flags, const char *file, const char *function, int line, Type type, const char *str,...)
Definition:
Log.cpp:106
Log::Severity
Severity
Definition:
Log.h:47
Log::TYPE_ERROR
@ TYPE_ERROR
Definition:
Log.h:39
Log::TERMINAL
@ TERMINAL
Definition:
Log.h:50
Log::Verbosity
Verbosity
Definition:
Log.h:52
Generated by
1.8.18