malcontent/nss/logger.hh

42 lines
1.0 KiB
C++
Raw Permalink Normal View History

2024-01-05 18:10:45 +01:00
// SPDX-FileCopyrightText: Matteo Settenvini <matteo.settenvini@montecristosoftware.eu>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <memory>
#include <shared_mutex>
#include <string_view>
namespace malcontent {
class Logger {
friend std::unique_ptr<Logger> std::make_unique<Logger>();
friend std::default_delete<Logger>;
public:
static auto debug(const std::string_view& msg) -> void;
static auto info(const std::string_view& msg) -> void;
static auto warn(const std::string_view& msg) -> void;
static auto error(const std::string_view& msg) -> void;
private:
Logger();
Logger(const Logger&) = delete;
Logger(Logger&&) = delete;
~Logger() noexcept;
auto operator=(const Logger&) = delete;
auto operator=(Logger&&) = delete;
auto log(int priority, std::string_view msg) -> void;
int _max_log_priority;
static auto instance() -> Logger&;
static std::unique_ptr<Logger> _instance;
static std::shared_mutex _instance_mtx;
};
} // ~ namespace malcontent