libcryfs/logging/Logger.h

57 lines
1.2 KiB
C
Raw Normal View History

2015-10-17 03:08:56 +02:00
#pragma once
#ifndef MESSMER_CPPUTILS_LOGGING_LOGGER_H
#define MESSMER_CPPUTILS_LOGGING_LOGGER_H
#include <messmer/spdlog/include/spdlog/spdlog.h>
#include "../macros.h"
namespace cpputils {
namespace logging {
class Logger {
public:
void setLogger(std::shared_ptr<spdlog::logger> logger) {
_logger = logger;
2015-10-17 15:49:54 +02:00
_logger->set_level(_level);
}
void reset() {
_level = spdlog::level::info;
setLogger(_defaultLogger());
}
void setLevel(spdlog::level::level_enum level) {
_level = level;
_logger->set_level(_level);
2015-10-17 03:08:56 +02:00
}
spdlog::logger *operator->() {
return _logger.get();
}
private:
2015-10-17 15:49:54 +02:00
static std::shared_ptr<spdlog::logger> _defaultLogger() {
static auto singleton = spdlog::stderr_logger_mt("Log");
2015-10-17 15:49:54 +02:00
return singleton;
}
Logger() : _logger(), _level() {
reset();
}
friend Logger &logger();
2015-10-17 03:08:56 +02:00
std::shared_ptr<spdlog::logger> _logger;
2015-10-17 15:49:54 +02:00
spdlog::level::level_enum _level;
2015-10-17 03:08:56 +02:00
DISALLOW_COPY_AND_ASSIGN(Logger);
};
inline Logger &logger() {
static Logger singleton;
return singleton;
}
}
}
#endif