mirror of https://github.com/gabime/spdlog.git
Remove context
parent
7cfe4fc0bc
commit
035efac8bc
@ -1,58 +0,0 @@
|
|||||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Loggers registry of unique name->logger pointer
|
|
||||||
// An attempt to create a logger with an already existing name will result with spdlog_ex exception.
|
|
||||||
// If user requests a non-existing logger, nullptr will be returned
|
|
||||||
// This class is thread safe
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <mutex>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "../common.h"
|
|
||||||
|
|
||||||
namespace spdlog {
|
|
||||||
class logger;
|
|
||||||
|
|
||||||
namespace details {
|
|
||||||
class thread_pool;
|
|
||||||
|
|
||||||
class SPDLOG_API context {
|
|
||||||
public:
|
|
||||||
context() = default;
|
|
||||||
explicit context(std::unique_ptr<logger> global_logger);
|
|
||||||
~context() = default;
|
|
||||||
context(const context &) = delete;
|
|
||||||
context &operator=(const context &) = delete;
|
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<logger> global_logger();
|
|
||||||
|
|
||||||
// Return raw ptr to the global logger.
|
|
||||||
// To be used directly by the spdlog global api (e.g. spdlog::info)
|
|
||||||
// This make the global API faster, but cannot be used concurrently with set_global_logger().
|
|
||||||
// e.g do not call set_global_logger() from one thread while calling spdlog::info() from
|
|
||||||
// another.
|
|
||||||
[[nodiscard]] logger *global_logger_raw() const noexcept;
|
|
||||||
|
|
||||||
// set logger instance.
|
|
||||||
void set_logger(std::shared_ptr<logger> new_logger);
|
|
||||||
|
|
||||||
void set_tp(std::shared_ptr<thread_pool> tp);
|
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<thread_pool> get_tp();
|
|
||||||
|
|
||||||
// clean all resources
|
|
||||||
void shutdown();
|
|
||||||
[[nodiscard]] std::recursive_mutex &tp_mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::recursive_mutex tp_mutex_;
|
|
||||||
std::shared_ptr<thread_pool> tp_;
|
|
||||||
std::shared_ptr<logger> global_logger_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace details
|
|
||||||
} // namespace spdlog
|
|
@ -1,44 +0,0 @@
|
|||||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
||||||
|
|
||||||
#include "spdlog/details/context.h"
|
|
||||||
#include "spdlog/logger.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace spdlog {
|
|
||||||
namespace details {
|
|
||||||
|
|
||||||
context::context(std::unique_ptr<logger> global_logger) { global_logger_ = std::move(global_logger); }
|
|
||||||
|
|
||||||
std::shared_ptr<logger> context::global_logger() { return global_logger_; }
|
|
||||||
|
|
||||||
// Return raw ptr to the global logger.
|
|
||||||
// To be used directly by the spdlog default api (e.g. spdlog::info)
|
|
||||||
// This make the default API faster, but cannot be used concurrently with set_global_logger().
|
|
||||||
// e.g do not call set_global_logger() from one thread while calling spdlog::info() from another.
|
|
||||||
logger *context::global_logger_raw() const noexcept { return global_logger_.get(); }
|
|
||||||
|
|
||||||
// set global logger
|
|
||||||
void context::set_logger(std::shared_ptr<logger> new_global_logger) { global_logger_ = std::move(new_global_logger); }
|
|
||||||
|
|
||||||
void context::set_tp(std::shared_ptr<thread_pool> tp) {
|
|
||||||
std::lock_guard lock(tp_mutex_);
|
|
||||||
tp_ = std::move(tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<thread_pool> context::get_tp() {
|
|
||||||
std::lock_guard lock(tp_mutex_);
|
|
||||||
return tp_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean all resources and threads started by the registry
|
|
||||||
void context::shutdown() {
|
|
||||||
std::lock_guard lock(tp_mutex_);
|
|
||||||
tp_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::recursive_mutex &context::tp_mutex() { return tp_mutex_; }
|
|
||||||
|
|
||||||
} // namespace details
|
|
||||||
} // namespace spdlog
|
|
Loading…
Reference in New Issue