2014-10-28 03:36:00 -04:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-10-28 03:36:00 -04:00
|
|
|
// Refer to the license.txt file included.
|
2021-06-13 10:31:47 -04:00
|
|
|
|
2014-10-28 03:36:00 -04:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-25 19:32:56 -04:00
|
|
|
#include <filesystem>
|
2018-07-02 13:10:41 -04:00
|
|
|
#include <memory>
|
2015-05-12 01:19:44 -04:00
|
|
|
#include <string>
|
2018-07-20 15:27:17 -04:00
|
|
|
#include <string_view>
|
2018-07-02 13:10:41 -04:00
|
|
|
#include "common/logging/filter.h"
|
2014-10-28 03:36:00 -04:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
|
2021-06-13 07:52:02 -04:00
|
|
|
namespace Common::FS {
|
|
|
|
class IOFile;
|
|
|
|
}
|
|
|
|
|
2021-04-14 20:19:52 -04:00
|
|
|
namespace Common::Log {
|
2014-10-28 03:36:00 -04:00
|
|
|
|
2015-05-12 01:19:44 -04:00
|
|
|
class Filter;
|
|
|
|
|
2018-07-02 13:10:41 -04:00
|
|
|
/**
|
|
|
|
* 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;
|
2021-06-13 07:52:02 -04:00
|
|
|
|
2018-07-02 13:10:41 -04:00
|
|
|
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:
|
2021-06-13 07:52:02 -04:00
|
|
|
~ConsoleBackend() override;
|
|
|
|
|
2018-07-02 13:10:41 -04:00
|
|
|
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:
|
2021-06-13 07:52:02 -04:00
|
|
|
~ColorConsoleBackend() override;
|
|
|
|
|
2018-07-02 13:10:41 -04:00
|
|
|
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:
|
2021-05-25 19:32:56 -04:00
|
|
|
explicit FileBackend(const std::filesystem::path& filename);
|
2021-06-13 07:52:02 -04:00
|
|
|
~FileBackend() override;
|
2018-07-02 13:10:41 -04:00
|
|
|
|
|
|
|
static const char* Name() {
|
|
|
|
return "file";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* GetName() const override {
|
|
|
|
return Name();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Write(const Entry& entry) override;
|
|
|
|
|
|
|
|
private:
|
2021-06-13 07:52:02 -04:00
|
|
|
std::unique_ptr<FS::IOFile> file;
|
2021-04-20 12:57:45 -04:00
|
|
|
std::size_t bytes_written = 0;
|
2018-07-02 13:10:41 -04:00
|
|
|
};
|
|
|
|
|
2018-10-04 23:22:49 -04:00
|
|
|
/**
|
|
|
|
* Backend that writes to Visual Studio's output window
|
|
|
|
*/
|
|
|
|
class DebuggerBackend : public Backend {
|
|
|
|
public:
|
2021-06-13 07:52:02 -04:00
|
|
|
~DebuggerBackend() override;
|
|
|
|
|
2018-10-04 23:22:49 -04:00
|
|
|
static const char* Name() {
|
|
|
|
return "debugger";
|
|
|
|
}
|
|
|
|
const char* GetName() const override {
|
|
|
|
return Name();
|
|
|
|
}
|
|
|
|
void Write(const Entry& entry) override;
|
|
|
|
};
|
|
|
|
|
2018-07-02 13:10:41 -04:00
|
|
|
void AddBackend(std::unique_ptr<Backend> backend);
|
|
|
|
|
2018-07-20 15:27:17 -04:00
|
|
|
void RemoveBackend(std::string_view backend_name);
|
2018-07-02 13:10:41 -04:00
|
|
|
|
2018-07-20 15:27:17 -04:00
|
|
|
Backend* GetBackend(std::string_view backend_name);
|
2018-07-02 13:10:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2021-04-14 20:19:52 -04:00
|
|
|
} // namespace Common::Log
|