mirror of https://github.com/gabime/spdlog.git
lite wip
parent
043c4acc7e
commit
57a312cb1a
@ -0,0 +1,13 @@
|
|||||||
|
project(spdlog-lite-example CXX)
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
set(LITE_SOURCES example.cpp create_lite.cpp)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${LITE_SOURCES})
|
||||||
|
|
||||||
|
include_directories(../lite)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog_lite)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
|
||||||
|
spdlog::lite::logger spdlog::create_lite(void* ctx)
|
||||||
|
{
|
||||||
|
if(ctx) {
|
||||||
|
//..
|
||||||
|
}
|
||||||
|
auto logger_impl = spdlog::default_logger();
|
||||||
|
logger_impl->set_level(spdlog::level::trace);
|
||||||
|
return spdlog::lite::logger(logger_impl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
auto l = spdlog::create_lite();
|
||||||
|
l.trace("HELLO {}!!!", "lite");
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
project(spdlog_lite)
|
||||||
|
|
||||||
|
add_library(spdlog_lite logger.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(spdlog_lite spdlog::spdlog)
|
@ -0,0 +1,21 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "spdlog/logger.h"
|
||||||
|
|
||||||
|
spdlog::lite::logger::logger(std::shared_ptr<spdlog::logger> impl)
|
||||||
|
{
|
||||||
|
impl_ = std::move(impl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool spdlog::lite::logger::should_log(spdlog::lite::level lvl) const SPDLOG_NOEXCEPT
|
||||||
|
{
|
||||||
|
auto spd_level = static_cast<spdlog::level::level_enum >(lvl);
|
||||||
|
return impl_->should_log(spd_level);//TODO level
|
||||||
|
}
|
||||||
|
|
||||||
|
void spdlog::lite::logger::log_formatted_(spdlog::lite::level lvl, const fmt::memory_buffer &formatted)
|
||||||
|
{
|
||||||
|
auto spd_level = static_cast<spdlog::level::level_enum >(lvl);
|
||||||
|
impl_->log(spd_level, spdlog::details::fmt_helper::to_string_view(formatted)); //TODO and source_loc
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
//
|
||||||
|
// Created by gabi on 3/16/19.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SPDLOG_LIB_LOGGER_H
|
||||||
|
#define SPDLOG_LIB_LOGGER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "spd_types.h"
|
||||||
|
#include "spdlog/fmt/fmt.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace spdlog {
|
||||||
|
class logger;
|
||||||
|
|
||||||
|
namespace lite {
|
||||||
|
class logger {
|
||||||
|
public:
|
||||||
|
logger() = default;
|
||||||
|
|
||||||
|
logger(std::shared_ptr<spdlog::logger> impl);
|
||||||
|
logger(const logger&) = default;
|
||||||
|
logger(logger&&) = default;
|
||||||
|
logger& operator=(const logger&) = default;
|
||||||
|
|
||||||
|
~logger() = default;
|
||||||
|
|
||||||
|
bool should_log(spdlog::lite::level lvl) const noexcept;
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void log(spdlog::lite::level lvl, const char *fmt, const Args &... args) {
|
||||||
|
if (!should_log(lvl)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fmt::memory_buffer formatted_buf;
|
||||||
|
fmt::format_to(formatted_buf, fmt, args...);
|
||||||
|
log_formatted_(lvl, formatted_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename... Args>
|
||||||
|
// void log(spdlog::lite::level lvl, const char *fmt, const Args &... args)
|
||||||
|
// {
|
||||||
|
// log(lvl, fmt, args...);
|
||||||
|
// }
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void trace(const char *fmt, const Args &... args) {
|
||||||
|
log(spdlog::lite::level::trace, fmt, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<spdlog::logger> impl_;
|
||||||
|
|
||||||
|
void log_formatted_(spdlog::lite::level lvl, const fmt::memory_buffer &formatted);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace lite
|
||||||
|
|
||||||
|
// factory to create lite logger
|
||||||
|
// implement it in a dedicated compilation unit for fast compiles
|
||||||
|
spdlog::lite::logger create_lite(void* ctx = nullptr);
|
||||||
|
} // namespace spdlog
|
||||||
|
#endif //SPDLOG_LIB_LOGGER_H
|
@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// Copyright(c) 2019 Gabi Melman.
|
||||||
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
//
|
||||||
|
|
||||||
|
// core types, forward declarations and defines used by spdlog
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace spdlog
|
||||||
|
{
|
||||||
|
namespace lite
|
||||||
|
{
|
||||||
|
enum class level{
|
||||||
|
trace,
|
||||||
|
debug,
|
||||||
|
info,
|
||||||
|
warning,
|
||||||
|
error,
|
||||||
|
critical,
|
||||||
|
off
|
||||||
|
|
||||||
|
};
|
||||||
|
}}
|
Loading…
Reference in New Issue