Hymn to Beauty
C++ 3D Engine
Log.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <sstream>
5#include <ctime>
6#include <glm/glm.hpp>
7#include <functional>
8
10
16class Log {
17 public:
18 enum Channel {
19 DEFAULT = 0,
24 };
25
27 explicit Log(const Channel channel = DEFAULT);
28
30 ~Log();
31
33
37 Log& operator<<(const std::string& text);
38
40
44 Log& operator<<(const int value);
45
47
51 Log& operator<<(const unsigned int value);
52
54
58 Log& operator<<(const unsigned long value);
59
61
65 Log& operator<<(const unsigned long long value);
66
68
72 Log& operator<<(const float value);
73
75
79 Log& operator<<(const double value);
80
82
87 Log& operator<<(const time_t value);
88
90
94 Log& operator<<(const glm::vec2& value);
95
97
101 Log& operator<<(const glm::vec3& value);
102
104
108 Log& operator<<(const glm::vec4& value);
109
111
115 static void SetupCallback(std::function<void(const Channel channel, const std::string& message)> callback);
116
118 static void ResetCallback();
119
121
124 static void SetupFile(const std::string& filename);
125
127 static void CloseFile();
128
129 private:
130 Channel currentChannel;
131 std::stringstream message;
132};
Logging class.
Definition: Log.hpp:16
~Log()
Destructor.
Definition: Log.cpp:25
Log & operator<<(const std::string &text)
Output some text.
Definition: Log.cpp:69
static void ResetCallback()
Remove the callback function.
Definition: Log.cpp:137
Channel
Definition: Log.hpp:18
@ DEFAULT
Default channel.
Definition: Log.hpp:19
@ NUMBER_OF_CHANNELS
Maximum number of channels, ensure this is the last element of the enum if adding channels.
Definition: Log.hpp:23
@ WARNING
Warnings.
Definition: Log.hpp:21
@ INFO
Information.
Definition: Log.hpp:20
@ ERR
Error.
Definition: Log.hpp:22
static void SetupCallback(std::function< void(const Channel channel, const std::string &message)> callback)
Setup callback.
Definition: Log.cpp:132
Log(const Channel channel=DEFAULT)
Constructor.
Definition: Log.cpp:19
static void SetupFile(const std::string &filename)
Setup file to log to.
Definition: Log.cpp:141
static void CloseFile()
Close any open logging file.
Definition: Log.cpp:147