2014-10-28 07:36:00 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-10-28 07:36:00 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-05-12 05:19:44 +00:00
|
|
|
#include <chrono>
|
2014-10-28 07:36:00 +00:00
|
|
|
#include <cstdarg>
|
2018-02-20 00:51:27 +00:00
|
|
|
#include <memory>
|
2015-05-12 05:19:44 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2018-02-20 04:35:57 +00:00
|
|
|
#include <boost/optional.hpp>
|
2018-02-20 00:51:27 +00:00
|
|
|
#include "common/file_util.h"
|
|
|
|
#include "common/logging/filter.h"
|
2014-10-28 07:36:00 +00:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
|
|
|
|
namespace Log {
|
|
|
|
|
2015-05-12 05:19:44 +00:00
|
|
|
class Filter;
|
|
|
|
|
2018-02-20 00:51:27 +00: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;
|
|
|
|
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:
|
|
|
|
const char* GetName() const override {
|
|
|
|
return "console";
|
|
|
|
}
|
|
|
|
void Write(const Entry& entry) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend that writes to stderr and with color
|
|
|
|
*/
|
|
|
|
class ColorConsoleBackend : public Backend {
|
|
|
|
public:
|
|
|
|
const char* GetName() const override {
|
|
|
|
return "color_console";
|
|
|
|
}
|
|
|
|
void Write(const Entry& entry) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-02-23 07:33:44 +00:00
|
|
|
* Backend that writes to a file passed into the constructor. If a log level is error or higher, it
|
|
|
|
* will flush immediately after writing
|
2018-02-20 00:51:27 +00:00
|
|
|
*/
|
|
|
|
class FileBackend : public Backend {
|
|
|
|
public:
|
2018-02-23 07:33:44 +00:00
|
|
|
explicit FileBackend(const std::string& filename);
|
2018-02-20 00:51:27 +00:00
|
|
|
|
|
|
|
const char* GetName() const override {
|
|
|
|
return "file";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Write(const Entry& entry) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FileUtil::IOFile file;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AddBackend(std::unique_ptr<Backend> backend);
|
|
|
|
|
|
|
|
void RemoveBackend(const std::string& backend_name);
|
|
|
|
|
2018-02-20 04:35:57 +00:00
|
|
|
boost::optional<Backend*> GetBackend(const std::string& backend_name);
|
2018-02-20 00:51:27 +00:00
|
|
|
|
2014-10-28 07:36:00 +00:00
|
|
|
/**
|
2015-05-12 05:19:44 +00:00
|
|
|
* Returns the name of the passed log class as a C-string. Subclasses are separated by periods
|
|
|
|
* instead of underscores as in the enumeration.
|
2014-10-28 07:36:00 +00:00
|
|
|
*/
|
2015-05-12 05:19:44 +00:00
|
|
|
const char* GetLogClassName(Class log_class);
|
2014-10-28 07:36:00 +00:00
|
|
|
|
2015-05-12 05:19:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the name of the passed log level as a C-string.
|
|
|
|
*/
|
|
|
|
const char* GetLevelName(Level log_level);
|
2014-10-28 07:36:00 +00:00
|
|
|
|
2018-02-20 00:51:27 +00: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);
|
2014-10-28 07:36:00 +00:00
|
|
|
|
2018-02-20 00:51:27 +00:00
|
|
|
} // namespace Log
|