summaryrefslogtreecommitdiffstats
path: root/src/common/logging/backend.h
diff options
context:
space:
mode:
authorJames Rowe <jroweboy@gmail.com>2018-07-02 19:10:41 +0200
committerbunnei <bunneidev@gmail.com>2018-07-03 03:45:47 +0200
commit6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff (patch)
treec69305f1bca02461e4af8dc20f0b47601f276fc0 /src/common/logging/backend.h
parentUpdate clang format (diff)
downloadyuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.tar
yuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.tar.gz
yuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.tar.bz2
yuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.tar.lz
yuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.tar.xz
yuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.tar.zst
yuzu-6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff.zip
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 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-
#pragma once
#include <chrono>
#include <cstdarg>
+#include <memory>
#include <string>
#include <utility>
+#include "common/file_util.h"
+#include "common/logging/filter.h"
#include "common/logging/log.h"
namespace Log {
@@ -35,6 +37,80 @@ struct Entry {
};
/**
+ * Interface for logging backends. As loggers can be created and removed at runtime, this can be
+ * used by a frontend for adding a custom logging backend as needed
+ */
+class Backend {
+public:
+ virtual ~Backend() = default;
+ virtual void SetFilter(const Filter& new_filter) {
+ filter = new_filter;
+ }
+ virtual const char* GetName() const = 0;
+ virtual void Write(const Entry& entry) = 0;
+
+private:
+ Filter filter;
+};
+
+/**
+ * Backend that writes to stderr without any color commands
+ */
+class ConsoleBackend : public Backend {
+public:
+ static const char* Name() {
+ return "console";
+ }
+ const char* GetName() const override {
+ return Name();
+ }
+ void Write(const Entry& entry) override;
+};
+
+/**
+ * Backend that writes to stderr and with color
+ */
+class ColorConsoleBackend : public Backend {
+public:
+ static const char* Name() {
+ return "color_console";
+ }
+
+ const char* GetName() const override {
+ return Name();
+ }
+ void Write(const Entry& entry) override;
+};
+
+/**
+ * Backend that writes to a file passed into the constructor
+ */
+class FileBackend : public Backend {
+public:
+ explicit FileBackend(const std::string& filename);
+
+ static const char* Name() {
+ return "file";
+ }
+
+ const char* GetName() const override {
+ return Name();
+ }
+
+ void Write(const Entry& entry) override;
+
+private:
+ FileUtil::IOFile file;
+ size_t bytes_written;
+};
+
+void AddBackend(std::unique_ptr<Backend> backend);
+
+void RemoveBackend(const std::string& backend_name);
+
+Backend* GetBackend(const std::string& backend_name);
+
+/**
* Returns the name of the passed log class as a C-string. Subclasses are separated by periods
* instead of underscores as in the enumeration.
*/
@@ -49,5 +125,10 @@ const char* GetLevelName(Level log_level);
Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
const char* function, std::string message);
-void SetFilter(Filter* filter);
-} // namespace Log
+/**
+ * The global filter will prevent any messages from even being processed if they are filtered. Each
+ * backend can have a filter, but if the level is lower than the global filter, the backend will
+ * never get the message
+ */
+void SetGlobalFilter(const Filter& filter);
+} // namespace Log \ No newline at end of file