SGCT master (487fac4)
Simple Graphics Cluster Toolkit
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/*****************************************************************************************
2 * SGCT *
3 * Simple Graphics Cluster Toolkit *
4 * *
5 * Copyright (c) 2012-2026 *
6 * For conditions of distribution and use, see copyright notice in LICENSE.md *
7 ****************************************************************************************/
8
9#ifndef __SGCT__LOGGER__H__
10#define __SGCT__LOGGER__H__
11
12#include <sgct/sgctexports.h>
13
14#include <functional>
15#include <mutex>
16#include <string>
17#include <string_view>
18#include <vector>
19
20namespace sgct {
21
22class SGCT_EXPORT Log {
23public:
27 enum class Level { Error = 3, Warning = 2, Info = 1, Debug = 0 };
28
29 static Log& instance();
30 static void destroy();
31
32 static void Debug(std::string_view message);
33 static void Warning(std::string_view message);
34 static void Info(std::string_view message);
35 static void Error(std::string_view message);
36
41
45 void setShowTime(bool state);
46
50 void setShowLogLevel(bool state);
51
55 void setLogToConsole(bool state);
56
61 void setLogCallback(std::function<void(Level, std::string_view)> fn);
62
63private:
64 Log();
65 Log(const Log&) = delete;
66 Log(Log&&) = delete;
67 Log& operator=(const Log&) = delete;
68 Log& operator=(Log&&) = delete;
69
70 void printv(Level level, std::string message);
71
72 static Log* _instance;
73
74 std::vector<char> _parseBuffer;
75
76 Level _level = Level::Info;
77 bool _showTime = false;
78 bool _showLevel = true;
79 bool _logToConsole = true;
80
81 std::mutex _mutex;
82
83 std::function<void(Level, std::string_view)> _messageCallback;
84};
85
86} // namespace sgct
87
88#endif // __SGCT__LOGGER__H__
static void Debug(std::string_view message)
void setShowLogLevel(bool state)
Sets whether the log level should be displayed with each print message.
void setLogToConsole(bool state)
Set if log to console should be enabled.
void setNotifyLevel(Level nl)
Set the notify level for displaying messages.
Level
Different notify levels for messages.
Definition log.h:27
@ Info
Definition log.h:27
static Log & instance()
void setLogCallback(std::function< void(Level, std::string_view)> fn)
Set the callback that gets invoked for each log.
void setShowTime(bool state)
Set whether time of day should be displayed with each print message.
static void Warning(std::string_view message)
static void Info(std::string_view message)
static void destroy()
static void Error(std::string_view message)
Definition actions.h:16