spdlog/lite/spdlite.cpp

88 lines
2.3 KiB
C++
Raw Normal View History

2019-03-23 11:25:50 -04:00
#include "spdlite.h"
2019-03-23 07:31:57 -04:00
#include "spdlog/spdlog.h"
#include "spdlog/logger.h"
2019-03-23 10:39:32 -04:00
static spdlog::level::level_enum to_spdlog_level(spdlog::lite::level level)
2019-03-23 10:15:58 -04:00
{
2019-03-23 10:39:32 -04:00
return static_cast<spdlog::level::level_enum>(level);
2019-03-23 10:15:58 -04:00
}
static spdlog::lite::level to_lite_level(spdlog::level::level_enum level)
{
return static_cast<spdlog::lite::level>(level);
}
2019-03-23 07:31:57 -04:00
spdlog::lite::logger::logger(std::shared_ptr<spdlog::logger> impl)
{
impl_ = std::move(impl);
}
2019-03-23 10:15:58 -04:00
bool spdlog::lite::logger::should_log(spdlog::lite::level level) const SPDLOG_NOEXCEPT
2019-03-23 07:31:57 -04:00
{
2019-03-23 10:15:58 -04:00
auto spd_level = to_spdlog_level(level);
2019-03-23 13:34:50 -04:00
return impl_->should_log(spd_level); // TODO avoid the call using local level member?
2019-03-23 07:31:57 -04:00
}
2019-03-23 13:34:50 -04:00
void spdlog::lite::logger::log_formatted_(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const fmt::memory_buffer &formatted)
2019-03-23 10:15:58 -04:00
{
auto spd_level = to_spdlog_level(lvl);
spdlog::source_loc source_loc{src.filename, src.line, src.funcname};
impl_->log(source_loc, spd_level, spdlog::details::fmt_helper::to_string_view(formatted));
}
2019-03-23 14:06:49 -04:00
void spdlog::lite::logger::log_string_view_(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const string_view_t &sv)
2019-03-23 13:34:50 -04:00
{
2019-03-23 14:06:49 -04:00
auto spd_level = to_spdlog_level(lvl);
spdlog::source_loc source_loc{src.filename, src.line, src.funcname};
impl_->log(source_loc, spd_level, sv);
2019-03-23 13:34:50 -04:00
}
2019-03-23 14:06:49 -04:00
void spdlog::lite::logger::log_string_view_(spdlog::lite::level lvl, const string_view_t &sv)
{
log_string_view_(spdlog::lite::src_loc{}, lvl, sv);
}
2019-03-23 10:15:58 -04:00
void spdlog::lite::logger::set_level(spdlog::lite::level level)
{
auto spd_level = to_spdlog_level(level);
impl_->set_level(spd_level);
}
spdlog::lite::level spdlog::lite::logger::get_level() const
{
return to_lite_level(impl_->level());
}
std::string spdlog::lite::logger::name() const
{
return impl_->name();
}
void spdlog::lite::logger::flush()
{
impl_->flush();
}
void spdlog::lite::logger::flush_on(spdlog::lite::level level)
{
auto spd_level = to_spdlog_level(level);
impl_->flush_on(spd_level);
}
spdlog::lite::level spdlog::lite::logger::flush_level() const
{
return to_lite_level(impl_->flush_level());
}
// pattern
void spdlog::lite::logger::set_pattern(std::string pattern)
{
impl_->set_pattern(std::move(pattern));
}
spdlog::lite::logger &spdlog::lite::default_logger()
{
static spdlog::lite::logger s_default(spdlog::default_logger());
return s_default;
}