summaryrefslogtreecommitdiff
path: root/src/common/logging/backend.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/logging/backend.h')
-rw-r--r--src/common/logging/backend.h87
1 files changed, 84 insertions, 3 deletions
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index 7e81efb23..57cdf6b2d 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -1,13 +1,15 @@
1// Copyright 2014 Citra Emulator Project 1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4
5#pragma once 4#pragma once
6 5
7#include <chrono> 6#include <chrono>
8#include <cstdarg> 7#include <cstdarg>
8#include <memory>
9#include <string> 9#include <string>
10#include <utility> 10#include <utility>
11#include "common/file_util.h"
12#include "common/logging/filter.h"
11#include "common/logging/log.h" 13#include "common/logging/log.h"
12 14
13namespace Log { 15namespace Log {
@@ -35,6 +37,80 @@ struct Entry {
35}; 37};
36 38
37/** 39/**
40 * Interface for logging backends. As loggers can be created and removed at runtime, this can be
41 * used by a frontend for adding a custom logging backend as needed
42 */
43class Backend {
44public:
45 virtual ~Backend() = default;
46 virtual void SetFilter(const Filter& new_filter) {
47 filter = new_filter;
48 }
49 virtual const char* GetName() const = 0;
50 virtual void Write(const Entry& entry) = 0;
51
52private:
53 Filter filter;
54};
55
56/**
57 * Backend that writes to stderr without any color commands
58 */
59class ConsoleBackend : public Backend {
60public:
61 static const char* Name() {
62 return "console";
63 }
64 const char* GetName() const override {
65 return Name();
66 }
67 void Write(const Entry& entry) override;
68};
69
70/**
71 * Backend that writes to stderr and with color
72 */
73class ColorConsoleBackend : public Backend {
74public:
75 static const char* Name() {
76 return "color_console";
77 }
78
79 const char* GetName() const override {
80 return Name();
81 }
82 void Write(const Entry& entry) override;
83};
84
85/**
86 * Backend that writes to a file passed into the constructor
87 */
88class FileBackend : public Backend {
89public:
90 explicit FileBackend(const std::string& filename);
91
92 static const char* Name() {
93 return "file";
94 }
95
96 const char* GetName() const override {
97 return Name();
98 }
99
100 void Write(const Entry& entry) override;
101
102private:
103 FileUtil::IOFile file;
104 size_t bytes_written;
105};
106
107void AddBackend(std::unique_ptr<Backend> backend);
108
109void RemoveBackend(const std::string& backend_name);
110
111Backend* GetBackend(const std::string& backend_name);
112
113/**
38 * Returns the name of the passed log class as a C-string. Subclasses are separated by periods 114 * Returns the name of the passed log class as a C-string. Subclasses are separated by periods
39 * instead of underscores as in the enumeration. 115 * instead of underscores as in the enumeration.
40 */ 116 */
@@ -49,5 +125,10 @@ const char* GetLevelName(Level log_level);
49Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, 125Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
50 const char* function, std::string message); 126 const char* function, std::string message);
51 127
52void SetFilter(Filter* filter); 128/**
53} // namespace Log 129 * The global filter will prevent any messages from even being processed if they are filtered. Each
130 * backend can have a filter, but if the level is lower than the global filter, the backend will
131 * never get the message
132 */
133void SetGlobalFilter(const Filter& filter);
134} // namespace Log \ No newline at end of file