NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

NeLogger.h
1
11#pragma once
12
13#include <NeCoreLib.h>
14#include <mutex>
15#include <set>
16#include <string>
17
18// Uncomment this to turn off the logging system. The macros LogAssert,
19// LogError, LogWarning, and LogInformation expand to nothing. (Do this for
20// optimal performance.)
21//#define NE_NO_LOGGER
22
23 namespace NeuralEngine
24{
25 // Listeners subscribe to Logger to receive message strings.
26 class NE_IMPEXP Listener
27 {
28 public:
29 enum
30 {
31 LISTEN_FOR_NOTHING = 0x00000000,
32 LISTEN_FOR_ASSERTION = 0x00000001,
33 LISTEN_FOR_ERROR = 0x00000002,
34 LISTEN_FOR_WARNING = 0x00000004,
35 LISTEN_FOR_INFORMATION = 0x00000008,
36 LISTEN_FOR_ALL = 0xFFFFFFFF
37 };
38
39 // Construction and destruction.
40 virtual ~Listener();
41 Listener(int flags/* = LISTEN_FOR_NOTHING*/);
42
43 // What the listener wants to hear.
44 int GetFlags() const;
45
46 // Handlers for the messages received from the logger.
47 void Assertion(std::string const& message);
48 void Error(std::string const& message);
49 void Warning(std::string const& message);
50 void Information(std::string const& message);
51
52 private:
53 virtual void Report(std::string const& message) = 0;
54
55 int mFlags;
56 };
57
58 class NE_IMPEXP Logger
59 {
60 public:
61
78 Logger(char const* file, char const* function, int line,
79 std::string const& message);
80
81 // Notify current listeners about the logged information.
82 void Assertion();
83 void Error();
84 void Warning();
85 void Information();
86
87 static void Subscribe(Listener* listener);
88 static void Unsubscribe(Listener* listener);
89
90 private:
91 std::string mMessage;
92
93 static std::mutex msMutex;
94 static std::set<Listener*> msListeners;
95 };
96
97#if !defined(NE_NO_LOGGER)
98
99#define LogAssert(condition, message) \
100 if (!(condition)) \
101 { \
102 Logger(__FILE__, __FUNCTION__, __LINE__, message).Assertion(); \
103 }
104
105#define LogError(message) \
106 Logger(__FILE__, __FUNCTION__, __LINE__, message).Error();
107
108#define LogWarning(message) \
109 Logger(__FILE__, __FUNCTION__, __LINE__, message).Warning();
110
111#define LogInformation(message) \
112 Logger(__FILE__, __FUNCTION__, __LINE__, message).Information();
113
114#else
115
116 // No logging of assertions, warnings, errors, or information.
117#define LogAssert(condition, message)
118#define LogError(message)
119#define LogWarning(message)
120#define LogInformation(message)
121
122#endif
123}
NeuralEngine::Listener
Definition: NeLogger.h:27
NeuralEngine::Logger
Definition: NeLogger.h:59
NeuralEngine::Logger::Logger
Logger(char const *file, char const *function, int line, std::string const &message)
Constructor.
NeuralEngine
Definition: NeArray2.h:18