Skip to content

Commit

Permalink
Decrease log level
Browse files Browse the repository at this point in the history
  • Loading branch information
willdealtry committed May 2, 2024
1 parent 223906f commit d2c6d54
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions cpp/arcticdb/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ namespace arcticdb::log {

static const char* DefaultLogPattern = "%Y%m%d %H:%M:%S.%f %t %L %n | %v";


namespace {
std::shared_ptr<Loggers> loggers_instance_;
std::once_flag loggers_init_flag_;
}


struct Loggers::Impl
{
std::shared_ptr<Loggers> loggers_instance_;
std::once_flag loggers_init_flag_;
} // namespace

struct Loggers::Impl {
std::mutex config_mutex_;
std::unordered_map<std::string, spdlog::sink_ptr> sink_by_id_;
std::unique_ptr<spdlog::logger> unconfigured_ = std::make_unique<spdlog::logger>("arcticdb",
Expand Down Expand Up @@ -70,9 +66,8 @@ struct Loggers::Impl
spdlog::logger& logger_ref(std::unique_ptr<spdlog::logger>& src);
};


constexpr auto get_default_log_level() {
return spdlog::level::trace;
return spdlog::level::info;
}

spdlog::logger &storage() {
Expand Down Expand Up @@ -128,15 +123,13 @@ namespace fs = std::filesystem;
using SinkConf = arcticdb::proto::logger::SinkConfig;

Loggers::Loggers()
: impl_(std::make_unique<Impl>())
{
: impl_(std::make_unique<Impl>()) {
impl_->unconfigured_->set_level(get_default_log_level());
}

Loggers::~Loggers() = default;

Loggers& Loggers::instance()
{
Loggers& Loggers::instance() {
std::call_once(loggers_init_flag_, &Loggers::init);
return *loggers_instance_;
}
Expand Down Expand Up @@ -204,7 +197,6 @@ void Loggers::flush_all() {
snapshot().flush();
}


void Loggers::destroy_instance() {
loggers_instance_.reset();
}
Expand All @@ -213,7 +205,6 @@ void Loggers::init() {
loggers_instance_ = std::make_shared<Loggers>();
}


namespace {
std::string make_parent_dir(const std::string &p_str, std::string_view def_p_str) {
fs::path p;
Expand All @@ -236,7 +227,6 @@ spdlog::logger& Loggers::Impl::logger_ref(std::unique_ptr<spdlog::logger>& src)
return *unconfigured_;
}


bool Loggers::configure(const arcticdb::proto::logger::LoggersConfig &conf, bool force) {
auto lock = std::scoped_lock(impl_->config_mutex_);
if (!force && impl_->root_)
Expand Down Expand Up @@ -320,7 +310,6 @@ bool Loggers::configure(const arcticdb::proto::logger::LoggersConfig &conf, bool
check_and_configure("symbol", "root", impl_->symbol_);
check_and_configure("snapshot", "root", impl_->snapshot_);


if (auto flush_sec = util::as_opt(conf.flush_interval_seconds()).value_or(1); flush_sec != 0) {
impl_->periodic_worker_.emplace(
[loggers = std::weak_ptr(loggers_instance_)]() {
Expand All @@ -332,7 +321,6 @@ bool Loggers::configure(const arcticdb::proto::logger::LoggersConfig &conf, bool
return true;
}


void Loggers::Impl::configure_logger(
const arcticdb::proto::logger::LoggerConfig &conf,
const std::string &name,
Expand All @@ -354,18 +342,15 @@ void Loggers::Impl::configure_logger(
logger = std::make_unique<spdlog::logger>(fq_name, sink_ptrs.begin(), sink_ptrs.end());
}

if (!conf.pattern().empty()) {
if (!conf.pattern().empty())
logger->set_pattern(conf.pattern());
}
else {
else
logger->set_pattern(DefaultLogPattern);
}

if (conf.level() != 0) {
if (conf.level() != 0)
logger->set_level(static_cast<spdlog::level::level_enum>(conf.level() - 1));
} else {
else
logger->set_level(get_default_log_level());
}
}

}

0 comments on commit d2c6d54

Please sign in to comment.