moved macros to seprate headers

This commit is contained in:
gabime 2019-03-24 00:38:00 +02:00
parent 680f19a424
commit b1c90f08cc
4 changed files with 76 additions and 74 deletions

View File

@ -6,8 +6,8 @@ int main()
auto l = spdlog::create_lite();
l.set_level(spdlog::lite::level::trace);
l.trace_f("Hello %s ","GABI");
l.info_f("Hello %d", 12346);
l.warn_f("Hello %f", 12346.5656);
l.warn("Hello {}", 12346.5656);
}

View File

@ -1,6 +1,5 @@
#include "spdlite.h"
#include "spdlog/spdlog.h"
#include "spdlog/logger.h"
static spdlog::level::level_enum to_spdlog_level(spdlog::lite::level level)
{

View File

@ -8,69 +8,6 @@
#include <string>
#include "spdlog/fmt/fmt.h"
//
// 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__)
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_TRACE
#define SPDLITE_LOGGER_TRACE(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlog::lite::level::trace, __VA_ARGS__)
#define SPDLITE_TRACE(...) SPDLITE_LOGGER_TRACE(spdlog::lite::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, spdlog::lite::level::debug, __VA_ARGS__)
#define SPDLITE_DEBUG(...) SPDLITE_LOGGER_DEBUG(spdlog::lite::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, spdlog::lite::level::info, __VA_ARGS__)
#define SPDLITE_INFO(...) SPDLITE_LOGGER_INFO(spdlog::lite::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, spdlog::lite::level::warn, __VA_ARGS__)
#define SPDLITE_WARN(...) SPDLITE_LOGGER_WARN(spdlog::lite::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, spdlog::lite::level::err, __VA_ARGS__)
#define SPDLITE_ERROR(...) SPDLITE_LOGGER_ERROR(spdlog::lite::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, spdlog::lite::level::critical, __VA_ARGS__)
#define SPDLITE_CRITICAL(...) SPDLITE_LOGGER_CRITICAL(spdlog::lite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLITE_CRITICAL(...) (void)0
#endif
namespace spdlog {
class logger;
@ -85,13 +22,13 @@ using string_view_t = fmt::string_view;
enum class level
{
trace = SPDLITE_LEVEL_TRACE,
debug = SPDLITE_LEVEL_DEBUG,
info = SPDLITE_LEVEL_INFO,
warn = SPDLITE_LEVEL_WARN,
err = SPDLITE_LEVEL_ERROR,
critical = SPDLITE_LEVEL_CRITICAL,
off = SPDLITE_LEVEL_OFF
trace,
debug,
info,
warn,
err,
critical,
off
};
@ -121,7 +58,6 @@ public:
log_formatted_(lvl, formatted_buf);
}
// log string view
void log(spdlog::lite::level lvl, const string_view_t &sv);
void log_printf(spdlog::lite::level lvl, const char* format, va_list args);

67
lite/spdlite_macros.h Normal file
View File

@ -0,0 +1,67 @@
//
// Created by gabi on 3/24/19.
//
#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__)
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_TRACE
#define SPDLITE_LOGGER_TRACE(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlog::lite::level::trace, __VA_ARGS__)
#define SPDLITE_TRACE(...) SPDLITE_LOGGER_TRACE(spdlog::lite::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, spdlog::lite::level::debug, __VA_ARGS__)
#define SPDLITE_DEBUG(...) SPDLITE_LOGGER_DEBUG(spdlog::lite::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, spdlog::lite::level::info, __VA_ARGS__)
#define SPDLITE_INFO(...) SPDLITE_LOGGER_INFO(spdlog::lite::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, spdlog::lite::level::warn, __VA_ARGS__)
#define SPDLITE_WARN(...) SPDLITE_LOGGER_WARN(spdlog::lite::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, spdlog::lite::level::err, __VA_ARGS__)
#define SPDLITE_ERROR(...) SPDLITE_LOGGER_ERROR(spdlog::lite::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, spdlog::lite::level::critical, __VA_ARGS__)
#define SPDLITE_CRITICAL(...) SPDLITE_LOGGER_CRITICAL(spdlog::lite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLITE_CRITICAL(...) (void)0
#endif