Debian Codegraph @

Source/Core/Common/Logging/LogManager.h

raw symbols SCIP
1 // Copyright 2009 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <atomic>
8 #include <cstdarg>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "Common/BitSet.h"
14 #include "Common/Config/Config.h"
15 #include "Common/EnumMap.h"
16 #include "Common/Logging/Log.h"
17
18 namespace Common::Log
19 {
20 // This variable should only be read to update the effective log level, and its base layer should
21 // only be set when the user selects a new verbosity. Everything else should use the effective log
22 // level instead. When running a release build this prevents overwriting the LDEBUG config value
23 // with the clamped LINFO level.
24 extern const Config::Info<LogLevel> LOGGER_VERBOSITY;
25
26 // pure virtual interface
27 class LogListener
28 {
29 public:
30 virtual ~LogListener() = default;
31 virtual void Log(LogLevel level, const char* msg) = 0;
32
33 enum LISTENER
34 {
35 FILE_LISTENER = 0,
36 CONSOLE_LISTENER,
37 LOG_WINDOW_LISTENER,
38
39 NUMBER_OF_LISTENERS // Must be last
40 };
41 };
42
43 class LogManager final
44 {
45 public:
46 struct LogContainer
47 {
48 const char* m_short_name;
49 const char* m_full_name;
50 bool m_enable = false;
51 };
52
53 ~LogManager();
54
55 static LogManager* GetInstance();
56 static void Init();
57 static void Shutdown();
58
59 void Log(LogLevel level, LogType type, const char* file, int line, const char* message);
60 void LogWithFullPath(LogLevel level, LogType type, const char* file, int line,
61 const char* message);
62
63 // Use this function instead of LOGGER_VERBOSITY to determine which logs should be printed.
64 LogLevel GetEffectiveLogLevel() const;
65 void SetConfigLogLevel(LogLevel level);
66
67 void SetEnable(LogType type, bool enable);
68 bool IsEnabled(LogType type, LogLevel level = LogLevel::LNOTICE) const;
69
70 std::vector<LogContainer> GetLogTypes();
71
72 const char* GetShortName(LogType type) const;
73 const char* GetFullName(LogType type) const;
74
75 void RegisterListener(LogListener::LISTENER id, std::unique_ptr<LogListener> listener);
76 void EnableListener(LogListener::LISTENER id, bool enable);
77 bool IsListenerEnabled(LogListener::LISTENER id) const;
78
79 void SaveSettings();
80
81 private:
82 LogManager();
83
84 LogManager(const LogManager&) = delete;
85 LogManager& operator=(const LogManager&) = delete;
86 LogManager(LogManager&&) = delete;
87 LogManager& operator=(LogManager&&) = delete;
88
89 static std::string GetTimestamp();
90 void SetEffectiveLogLevel();
91
92 std::atomic<LogLevel> m_effective_level;
93 Config::ConfigChangedCallbackID m_config_changed_callback_id;
94 EnumMap<LogContainer, LAST_LOG_TYPE> m_log{};
95 std::array<std::unique_ptr<LogListener>, LogListener::NUMBER_OF_LISTENERS> m_listeners{};
96 BitSet32 m_listener_ids;
97 size_t m_path_cutoff_point = 0;
98 };
99 } // namespace Common::Log