removed spdlite

This commit is contained in:
gabime 2019-04-06 12:57:09 +03:00
parent fef405ac98
commit 7e29c48379
11 changed files with 3 additions and 669 deletions

View File

@ -54,7 +54,6 @@ option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/
option(SPDLOG_BUILD_TESTS "Build tests" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_BUILD_LITE "Build spdlog lite" ${SPDLOG_MASTER_PROJECT})
if(SPDLOG_FMT_EXTERNAL AND NOT TARGET fmt::fmt)
@ -88,10 +87,6 @@ if(SPDLOG_BUILD_BENCH)
add_subdirectory(bench)
endif()
if(SPDLOG_BUILD_LITE)
add_subdirectory(spdlite)
endif()
#---------------------------------------------------------------------------------------
# Install/export targets and files
#---------------------------------------------------------------------------------------

View File

@ -15,9 +15,7 @@ spdlog::logger *get_logger();
int main(int, char *[])
{
int x = 4;
spdlog::info("HELLO {}", "st at ic");
spdlog::warn("HELLO {} *{} = {}", x, x, x*x);
/*auto *l = get_logger();
l->info("HEllo {}", "HG FS");*/
auto *l = get_logger();
l->info("HEllo { }", "HG FS");
}

View File

@ -1,14 +0,0 @@
cmake_minimum_required(VERSION 3.1)
project(spdlite)
include_directories(${PROJECT_SOURCE_DIR}/include)
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
file(GLOB HEADER_FILES ${PROJECT_SOURCE_DIR}/include/*.h)
add_library(spdlite ${SRC_FILES} ${HEADER_FILES})
target_link_libraries(spdlite spdlog::spdlog)
add_subdirectory(example)

View File

@ -1,11 +0,0 @@
project(spdlite-example CXX)
set(LITE_SOURCES example.cpp create_logger.cpp)
add_executable(${PROJECT_NAME} ${LITE_SOURCES})
find_package(Threads)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
target_link_libraries(${PROJECT_NAME} PRIVATE spdlite)

View File

@ -1,16 +0,0 @@
// Copyright(c) 2015-present Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include "spdlite/spdlite.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#define UNUSED(x) (void)(x)
// example of creating lite logger with console and file sink
spdlite::logger create_logger(void *ctx)
{
UNUSED(ctx);
return spdlite::logger(spdlog::basic_logger_mt("logger-name", "log.txt", true));
}

View File

@ -1,12 +0,0 @@
// Copyright(c) 2015-present Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include "spdlite/spdlite.h"
#include "spdlite/default_api.h"
#define SPDLITE_ACTIVE_LEVEL SPDLITE_LEVEL_TRACE
#include "spdlite/spdlite_macros.h"
int main()
{
SPDLITE_TRACE("SOME INFO {}", 123);
}

View File

@ -1,95 +0,0 @@
// Copyright(c) 2015-present Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
#include "spdlite.h"
namespace spdlite
{
//
// spdlite namespace functions - forward the calls to the default_logger.
//
spdlite::logger &default_logger();
template<typename... Args>
inline void trace(const char *fmt, const Args &... args)
{
default_logger().trace(fmt, args...);
}
template<typename... Args>
inline void debug(const char *fmt, const Args &... args)
{
default_logger().debug(fmt, args...);
}
template<typename... Args>
inline void info(const char *fmt, const Args &... args)
{
default_logger().info(fmt, args...);
}
template<typename... Args>
inline void warn(const char *fmt, const Args &... args)
{
default_logger().warn(fmt, args...);
}
template<typename... Args>
inline void error(const char *fmt, const Args &... args)
{
default_logger().error(fmt, args...);
}
template<typename... Args>
inline void critical(const char *fmt, const Args &... args)
{
default_logger().critical(fmt, args...);
}
// string view convertable
template<typename T>
inline void trace(const T &msg)
{
default_logger().trace(msg);
}
template<typename T>
inline void debug(const T &msg)
{
default_logger().debug(msg);
}
template<typename T>
inline void info(const T &msg)
{
default_logger().info(msg);
}
template<typename T>
inline void warn(const T &msg)
{
default_logger().warn(msg);
}
template<typename T>
inline void error(const T &msg)
{
default_logger().error(msg);
}
template<typename T>
inline void critical(const T &msg)
{
default_logger().critical(msg);
}
void log_printf(spdlite::level lvl, const char *format, va_list args);
void trace_printf(const char *format, ...);
void debug_printf(const char *format, ...);
void info_printf(const char *format, ...);
void warn_printf(const char *format, ...);
void error_printf(const char *format, ...);
void critical_printf(const char *format, ...);
}

View File

@ -1,218 +0,0 @@
// Copyright(c) 2015-present Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
// lite logger - a pimpl around spdlog::logger shared_ptr:
// much faster compile times.
// can be used as lib or separate compilation unit.
// very cheap copy and move.
// supports printf format for even faster compile (by avoiding variadic templates).
//
// see lite-example/ for usage.
#include <memory>
#include <string>
#include "spdlog/fmt/fmt.h"
namespace spdlog {
class logger;
}
namespace spdlite {
// string_view type - either std::string_view or fmt::string_view (pre c++17)
#if defined(FMT_USE_STD_STRING_VIEW)
using string_view_t = std::string_view;
#else
using string_view_t = fmt::string_view;
#endif
enum class level
{
trace,
debug,
info,
warn,
err,
critical,
off
};
class logger
{
public:
explicit logger(std::shared_ptr<spdlog::logger> impl);
// logger() = default; //logger with nullptr impl
logger(const logger &) = default;
logger(logger &&) = default;
logger &operator=(const logger &) = default;
~logger() = default;
void set_impl(std::shared_ptr<spdlog::logger> impl);
bool should_log(spdlite::level lvl) const noexcept;
template<typename... Args>
void log(spdlite::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);
}
// log string view
void log(spdlite::level lvl, const string_view_t &sv);
//
// trace
//
void trace(const char *msg)
{
log(spdlite::level::trace, string_view_t(msg));
}
template<typename T>
void trace(const T &msg)
{
log(spdlite::level::trace, string_view_t(msg));
}
template<typename... Args>
void trace(const char *fmt, const Args &... args)
{
log(spdlite::level::trace, fmt, args...);
}
//
// debug
//
void debug(const char *msg)
{
log(spdlite::level::debug, string_view_t(msg));
}
template<typename T>
void debug(const T &msg)
{
log(spdlite::level::debug, string_view_t(msg));
}
template<typename... Args>
void debug(const char *fmt, const Args &... args)
{
log(spdlite::level::debug, fmt, args...);
}
// info
void info(const char *msg)
{
log(spdlite::level::info, string_view_t(msg));
}
template<typename T>
void info(const T &msg)
{
log(spdlite::level::info, string_view_t(msg));
}
template<typename... Args>
void info(const char *fmt, const Args &... args)
{
log(spdlite::level::info, fmt, args...);
}
// warn
void warn(const char *msg)
{
log(spdlite::level::warn, string_view_t(msg));
}
template<typename T>
void warn(const T &msg)
{
log(spdlite::level::warn, string_view_t(msg));
}
template<typename... Args>
void warn(const char *fmt, const Args &... args)
{
log(spdlite::level::warn, fmt, args...);
}
// error
void error(const char *msg)
{
log(spdlite::level::err, string_view_t(msg));
}
template<typename T>
void error(const T &msg)
{
log(spdlite::level::err, string_view_t(msg));
}
template<typename... Args>
void error(const char *fmt, const Args &... args)
{
log(spdlite::level::err, fmt, args...);
}
// critical
void critical(const char *msg)
{
log(spdlite::level::critical, string_view_t(msg));
}
template<typename T>
void critical(const T &msg)
{
log(spdlite::level::critical, string_view_t(msg));
}
template<typename... Args>
void critical(const char *fmt, const Args &... args)
{
log(spdlite::level::critical, fmt, args...);
}
// printf formatting
void log_printf(spdlite::level lvl, const char *format, va_list args);
void trace_printf(const char *format, ...);
void debug_printf(const char *format, ...);
void info_printf(const char *format, ...);
void warn_printf(const char *format, ...);
void error_printf(const char *format, ...);
void critical_printf(const char *format, ...);
// setters/getters
void set_level(spdlite::level level) noexcept;
void set_pattern(std::string pattern) noexcept;
spdlite::level level() const noexcept;
std::string name() const noexcept;
spdlite::level flush_level() const noexcept;
// flush
void flush();
void flush_on(spdlite::level log_level);
// clone with new name
spdlite::logger clone(std::string logger_name);
static spdlite::logger &default_logger();
protected:
std::shared_ptr<spdlog::logger> impl_;
void log_formatted_(spdlite::level lvl, const fmt::memory_buffer &formatted);
};
} // namespace spdlite
// user implemented factory to create lite logger
// implement it in a seperated and dedicated compilation unit for fast compiles.
spdlite::logger create_logger(void *ctx = nullptr);

View File

@ -1,75 +0,0 @@
// Copyright(c) 2015-present Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
//
// enable/disable log calls at compile time according to global level.
//
// define SPDLITE_ACTIVE_LEVEL to one of those (before including lite.h):
#define SPDLITE_LEVEL_TRACE 0
#define SPDLITE_LEVEL_DEBUG 1
#define SPDLITE_LEVEL_INFO 2
#define SPDLITE_LEVEL_WARN 3
#define SPDLITE_LEVEL_ERROR 4
#define SPDLITE_LEVEL_CRITICAL 5
#define SPDLITE_LEVEL_OFF 6
#define SPDLITE_LOGGER_CALL(logger, level, ...) logger.log(level, __VA_ARGS__)
// default level is info
#ifndef SPDLITE_ACTIVE_LEVEL
#define SPDLITE_ACTIVE_LEVEL SPDLITE_LEVEL_INFO
#endif
static_assert(SPDLITE_ACTIVE_LEVEL >= SPDLITE_LEVEL_TRACE && SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_OFF, "SPDLITE_ACTIVE_LEVEL");
#if SPDLITE_ACTIVE_LEVEL == SPDLITE_LEVEL_TRACE
#define SPDLITE_LOGGER_TRACE(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlite::level::trace, __VA_ARGS__)
#define SPDLITE_TRACE(...) SPDLITE_LOGGER_TRACE(spdlite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_TRACE(logger, ...) (void)0
#define SPDLITE_TRACE(...) (void)0
#endif
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_DEBUG
#define SPDLITE_LOGGER_DEBUG(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlite::level::debug, __VA_ARGS__)
#define SPDLITE_DEBUG(...) SPDLITE_LOGGER_DEBUG(spdlite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_DEBUG(logger, ...) (void)0
#define SPDLITE_DEBUG(...) (void)0
#endif
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_INFO
#define SPDLITE_LOGGER_INFO(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlite::level::info, __VA_ARGS__)
#define SPDLITE_INFO(...) SPDLITE_LOGGER_INFO(spdlite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_INFO(logger, ...) (void)0
#define SPDLITE_INFO(...) (void)0
#endif
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_WARN
#define SPDLITE_LOGGER_WARN(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlite::level::warn, __VA_ARGS__)
#define SPDLITE_WARN(...) SPDLITE_LOGGER_WARN(spdlite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_WARN(logger, ...) (void)0
#define SPDLITE_WARN(...) (void)0
#endif
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_ERROR
#define SPDLITE_LOGGER_ERROR(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlite::level::err, __VA_ARGS__)
#define SPDLITE_ERROR(...) SPDLITE_LOGGER_ERROR(spdlite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_ERROR(logger, ...) (void)0
#define SPDLITE_ERROR(...) (void)0
#endif
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_CRITICAL
#define SPDLITE_LOGGER_CRITICAL(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlite::level::critical, __VA_ARGS__)
#define SPDLITE_CRITICAL(...) SPDLITE_LOGGER_CRITICAL(spdlite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLITE_CRITICAL(...) (void)0
#endif

View File

@ -1,155 +0,0 @@
//
// Copyright(c) 2019-present spdlog
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#include "spdlite/spdlite.h"
#include "spdlog/spdlog.h"
static spdlog::level::level_enum to_spdlog_level(spdlite::level level)
{
return static_cast<spdlog::level::level_enum>(level);
}
static spdlite::level to_lite_level(spdlog::level::level_enum level)
{
return static_cast<spdlite::level>(level);
}
spdlite::logger::logger(std::shared_ptr<spdlog::logger> impl)
{
impl_ = std::move(impl);
}
void spdlite::logger::set_impl(std::shared_ptr<spdlog::logger> impl)
{
impl_ = std::move(impl);
}
bool spdlite::logger::should_log(spdlite::level level) const SPDLOG_NOEXCEPT
{
auto spd_level = to_spdlog_level(level);
return impl_->should_log(spd_level); // TODO avoid the call using local level member?
}
void spdlite::logger::log(spdlite::level lvl, const string_view_t &sv)
{
auto spd_level = to_spdlog_level(lvl);
impl_->log(spd_level, sv);
}
void spdlite::logger::log_printf(spdlite::level lvl, const char *format, va_list args)
{
char buffer[256];
auto size = vsnprintf(buffer, sizeof(buffer), format, args);
if (size < 0)
{
size = snprintf(buffer, sizeof(buffer), "invalid format (%s)", format);
}
log(lvl, string_view_t{buffer, static_cast<size_t>(size)});
}
void spdlite::logger::trace_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(spdlite::level::trace, format, args);
va_end(args);
}
void spdlite::logger::debug_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(spdlite::level::debug, format, args);
va_end(args);
}
void spdlite::logger::info_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(spdlite::level::info, format, args);
va_end(args);
}
void spdlite::logger::warn_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(spdlite::level::warn, format, args);
va_end(args);
}
void spdlite::logger::error_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(spdlite::level::err, format, args);
va_end(args);
}
void spdlite::logger::critical_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(spdlite::level::critical, format, args);
va_end(args);
}
void spdlite::logger::set_level(spdlite::level level) noexcept
{
auto spd_level = to_spdlog_level(level);
impl_->set_level(spd_level);
}
spdlite::level spdlite::logger::level() const noexcept
{
return to_lite_level(impl_->level());
}
std::string spdlite::logger::name() const noexcept
{
return impl_->name();
}
void spdlite::logger::flush()
{
impl_->flush();
}
void spdlite::logger::flush_on(spdlite::level level)
{
auto spd_level = to_spdlog_level(level);
impl_->flush_on(spd_level);
}
spdlite::level spdlite::logger::flush_level() const noexcept
{
return to_lite_level(impl_->flush_level());
}
// pattern
void spdlite::logger::set_pattern(std::string pattern) noexcept
{
impl_->set_pattern(std::move(pattern));
}
spdlite::logger spdlite::logger::clone(std::string logger_name)
{
return spdlite::logger(impl_->clone(std::move(logger_name)));
}
void spdlite::logger::log_formatted_(spdlite::level lvl, const fmt::memory_buffer &formatted)
{
auto spd_level = to_spdlog_level(lvl);
impl_->log(spd_level, spdlog::details::fmt_helper::to_string_view(formatted));
}
spdlite::logger &spdlite::logger::default_logger()
{
static spdlite::logger default_inst_ = spdlite::logger(spdlog::default_logger());
return default_inst_;
}

View File

@ -1,63 +0,0 @@
// Copyright(c) 2015-present Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include "spdlite/default_api.h"
spdlite::logger &spdlite::default_logger()
{
return spdlite::logger::default_logger();
}
// printf
void spdlite::log_printf(spdlite::level lvl, const char *format, va_list args)
{
default_logger().log_printf(lvl, format, args);
}
void spdlite::trace_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(level::trace, format, args);
va_end(args);
}
void spdlite::debug_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(level::debug, format, args);
va_end(args);
}
void spdlite::info_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(level::info, format, args);
va_end(args);
}
void spdlite::warn_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(level::warn, format, args);
va_end(args);
}
void spdlite::error_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(level::err, format, args);
va_end(args);
}
void spdlite::critical_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
log_printf(level::critical, format, args);
va_end(args);
}