fixed macros and other stuff for the no-streams branch
This commit is contained in:
parent
7885aa478c
commit
7ddfb2b877
@ -22,11 +22,11 @@ int main(int, char*[])
|
|||||||
// Multithreaded color console
|
// Multithreaded color console
|
||||||
auto console = spd::stdout_logger_mt("console", true);
|
auto console = spd::stdout_logger_mt("console", true);
|
||||||
console->info("Welcome to spdlog!");
|
console->info("Welcome to spdlog!");
|
||||||
console->info("An info message example {}..", 1);
|
console->error("An info message example {}..", 1);
|
||||||
|
|
||||||
// Formatting examples
|
// Formatting examples
|
||||||
console->info("Easy padding in numbers like {:08d}", 12);
|
console->warn("Easy padding in numbers like {:08d}", 12);
|
||||||
console->info("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||||
console->info("Support for floats {:03.2f}", 1.23456);
|
console->info("Support for floats {:03.2f}", 1.23456);
|
||||||
console->info("Positional args are {1} {0}..", "too", "supported");
|
console->info("Positional args are {1} {0}..", "too", "supported");
|
||||||
|
|
||||||
|
@ -56,26 +56,32 @@ using level_t = details::null_atomic_int;
|
|||||||
using level_t = std::atomic_int;
|
using level_t = std::atomic_int;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define SPDLOG_LEVEL_TRACE 0
|
||||||
|
#define SPDLOG_LEVEL_DEBUG 1
|
||||||
|
#define SPDLOG_LEVEL_INFO 2
|
||||||
|
#define SPDLOG_LEVEL_WARN 3
|
||||||
|
#define SPDLOG_LEVEL_ERR 4
|
||||||
|
#define SPDLOG_LEVEL_CRIT 5
|
||||||
|
#define SPDLOG_LEVEL_OFF 6
|
||||||
|
|
||||||
//Log level enum
|
//Log level enum
|
||||||
namespace level
|
namespace level
|
||||||
{
|
{
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
trace = 0,
|
trace = SPDLOG_LEVEL_TRACE,
|
||||||
debug = 1,
|
debug = SPDLOG_LEVEL_DEBUG,
|
||||||
info = 2,
|
info = SPDLOG_LEVEL_INFO,
|
||||||
notice = 3,
|
warn = SPDLOG_LEVEL_WARN,
|
||||||
warn = 4,
|
err = SPDLOG_LEVEL_ERR,
|
||||||
err = 5,
|
critical = SPDLOG_LEVEL_CRIT,
|
||||||
critical = 6,
|
off = SPDLOG_LEVEL_OFF
|
||||||
alert = 7,
|
|
||||||
emerg = 8,
|
|
||||||
off = 9
|
|
||||||
} level_enum;
|
} level_enum;
|
||||||
|
|
||||||
static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical", "alert", "emerg", "off"};
|
static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "off"};
|
||||||
|
|
||||||
static const char* short_level_names[] { "T", "D", "I", "N", "W", "E", "C", "A", "M", "O"};
|
static const char* short_level_names[] { "T", "D", "I", "W", "E", "C", "O"};
|
||||||
|
|
||||||
inline const char* to_str(spdlog::level::level_enum l)
|
inline const char* to_str(spdlog::level::level_enum l)
|
||||||
{
|
{
|
||||||
@ -124,5 +130,7 @@ using filename_t = std::wstring;
|
|||||||
using filename_t = std::string;
|
using filename_t = std::string;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SDLOG_STR_HELPER(x) #x
|
||||||
|
#define SPDLOG_STR(x) SDLOG_STR_HELPER(x)
|
||||||
|
|
||||||
} //spdlog
|
} //spdlog
|
||||||
|
@ -19,7 +19,7 @@ namespace details
|
|||||||
struct log_msg
|
struct log_msg
|
||||||
{
|
{
|
||||||
log_msg() = default;
|
log_msg() = default;
|
||||||
log_msg(std::string *loggers_name, level::level_enum lvl) : logger_name(loggers_name), level(lvl)
|
log_msg(const std::string *loggers_name, level::level_enum lvl) : logger_name(loggers_name), level(lvl)
|
||||||
{
|
{
|
||||||
#ifndef SPDLOG_NO_DATETIME
|
#ifndef SPDLOG_NO_DATETIME
|
||||||
time = os::now();
|
time = os::now();
|
||||||
@ -35,7 +35,7 @@ struct log_msg
|
|||||||
log_msg(log_msg&& other) = delete;
|
log_msg(log_msg&& other) = delete;
|
||||||
|
|
||||||
|
|
||||||
std::string *logger_name;
|
const std::string *logger_name;
|
||||||
level::level_enum level;
|
level::level_enum level;
|
||||||
log_clock::time_point time;
|
log_clock::time_point time;
|
||||||
size_t thread_id;
|
size_t thread_id;
|
||||||
|
@ -31,8 +31,7 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si
|
|||||||
|
|
||||||
// ctor with single sink
|
// ctor with single sink
|
||||||
inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink) :
|
inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink) :
|
||||||
logger(logger_name,
|
logger(logger_name, {
|
||||||
{
|
|
||||||
single_sink
|
single_sink
|
||||||
}) {}
|
}) {}
|
||||||
|
|
||||||
@ -54,8 +53,7 @@ inline void spdlog::logger::set_pattern(const std::string& pattern)
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Args&... args)
|
inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Args&... args)
|
||||||
{
|
{
|
||||||
if (!should_log(lvl))
|
if (!should_log(lvl)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
details::log_msg log_msg(&_name, lvl);
|
details::log_msg log_msg(&_name, lvl);
|
||||||
try
|
try
|
||||||
@ -75,9 +73,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
|
inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
|
||||||
{
|
{
|
||||||
|
if (!should_log(lvl)) return;
|
||||||
if (!should_log(lvl))
|
|
||||||
return;
|
|
||||||
|
|
||||||
details::log_msg log_msg(&_name, lvl);
|
details::log_msg log_msg(&_name, lvl);
|
||||||
log_msg.raw << msg;
|
log_msg.raw << msg;
|
||||||
@ -89,10 +85,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
|
inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
|
||||||
{
|
{
|
||||||
if (!should_log(lvl))
|
if (!should_log(lvl)) return;
|
||||||
return;
|
|
||||||
details::log_msg log_msg(&_name, lvl);
|
|
||||||
|
|
||||||
|
details::log_msg log_msg(&_name, lvl);
|
||||||
log_msg.raw << msg;
|
log_msg.raw << msg;
|
||||||
_formatter->format(log_msg);
|
_formatter->format(log_msg);
|
||||||
_sink_it(log_msg);
|
_sink_it(log_msg);
|
||||||
@ -118,11 +113,6 @@ inline void spdlog::logger::info(const char* fmt, const Args&... args)
|
|||||||
log(level::info, fmt, args...);
|
log(level::info, fmt, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline void spdlog::logger::notice(const char* fmt, const Args&... args)
|
|
||||||
{
|
|
||||||
log(level::notice, fmt, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline void spdlog::logger::warn(const char* fmt, const Args&... args)
|
inline void spdlog::logger::warn(const char* fmt, const Args&... args)
|
||||||
@ -142,19 +132,6 @@ inline void spdlog::logger::critical(const char* fmt, const Args&... args)
|
|||||||
log(level::critical, fmt, args...);
|
log(level::critical, fmt, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline void spdlog::logger::alert(const char* fmt, const Args&... args)
|
|
||||||
{
|
|
||||||
log(level::alert, fmt, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline void spdlog::logger::emerg(const char* fmt, const Args&... args)
|
|
||||||
{
|
|
||||||
log(level::emerg, fmt, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void spdlog::logger::trace(const T& msg)
|
inline void spdlog::logger::trace(const T& msg)
|
||||||
@ -175,11 +152,6 @@ inline void spdlog::logger::info(const T& msg)
|
|||||||
log(level::info, msg);
|
log(level::info, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline void spdlog::logger::notice(const T& msg)
|
|
||||||
{
|
|
||||||
log(level::notice, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void spdlog::logger::warn(const T& msg)
|
inline void spdlog::logger::warn(const T& msg)
|
||||||
@ -199,17 +171,6 @@ inline void spdlog::logger::critical(const T& msg)
|
|||||||
log(level::critical, msg);
|
log(level::critical, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline void spdlog::logger::alert(const T& msg)
|
|
||||||
{
|
|
||||||
log(level::alert, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline void spdlog::logger::emerg(const T& msg)
|
|
||||||
{
|
|
||||||
log(level::emerg, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,30 +35,24 @@ public:
|
|||||||
logger(const logger&) = delete;
|
logger(const logger&) = delete;
|
||||||
logger& operator=(const logger&) = delete;
|
logger& operator=(const logger&) = delete;
|
||||||
|
|
||||||
|
|
||||||
template <typename... Args> void log(level::level_enum lvl, const char* fmt, const Args&... args);
|
template <typename... Args> void log(level::level_enum lvl, const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void log(level::level_enum lvl, const char* msg);
|
template <typename... Args> void log(level::level_enum lvl, const char* msg);
|
||||||
|
|
||||||
template <typename T> void log(level::level_enum lvl, const T&);
|
|
||||||
template <typename... Args> void trace(const char* fmt, const Args&... args);
|
template <typename... Args> void trace(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void debug(const char* fmt, const Args&... args);
|
template <typename... Args> void debug(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void info(const char* fmt, const Args&... args);
|
template <typename... Args> void info(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void notice(const char* fmt, const Args&... args);
|
|
||||||
template <typename... Args> void warn(const char* fmt, const Args&... args);
|
template <typename... Args> void warn(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void error(const char* fmt, const Args&... args);
|
template <typename... Args> void error(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void critical(const char* fmt, const Args&... args);
|
template <typename... Args> void critical(const char* fmt, const Args&... args);
|
||||||
template <typename... Args> void alert(const char* fmt, const Args&... args);
|
|
||||||
template <typename... Args> void emerg(const char* fmt, const Args&... args);
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T> void log(level::level_enum lvl, const T&);
|
||||||
template <typename T> void trace(const T&);
|
template <typename T> void trace(const T&);
|
||||||
template <typename T> void debug(const T&);
|
template <typename T> void debug(const T&);
|
||||||
template <typename T> void info(const T&);
|
template <typename T> void info(const T&);
|
||||||
template <typename T> void notice(const T&);
|
|
||||||
template <typename T> void warn(const T&);
|
template <typename T> void warn(const T&);
|
||||||
template <typename T> void error(const T&);
|
template <typename T> void error(const T&);
|
||||||
template <typename T> void critical(const T&);
|
template <typename T> void critical(const T&);
|
||||||
template <typename T> void alert(const T&);
|
|
||||||
template <typename T> void emerg(const T&);
|
|
||||||
|
|
||||||
bool should_log(level::level_enum) const;
|
bool should_log(level::level_enum) const;
|
||||||
void set_level(level::level_enum);
|
void set_level(level::level_enum);
|
||||||
@ -76,7 +70,7 @@ protected:
|
|||||||
virtual void _set_pattern(const std::string&);
|
virtual void _set_pattern(const std::string&);
|
||||||
virtual void _set_formatter(formatter_ptr);
|
virtual void _set_formatter(formatter_ptr);
|
||||||
|
|
||||||
std::string _name;
|
const std::string _name;
|
||||||
std::vector<sink_ptr> _sinks;
|
std::vector<sink_ptr> _sinks;
|
||||||
formatter_ptr _formatter;
|
formatter_ptr _formatter;
|
||||||
spdlog::level_t _level;
|
spdlog::level_t _level;
|
||||||
|
@ -74,13 +74,10 @@ inline ansicolor_sink::ansicolor_sink(sink_ptr wrapped_sink) : sink_(wrapped_sin
|
|||||||
{
|
{
|
||||||
colors_[level::trace] = cyan;
|
colors_[level::trace] = cyan;
|
||||||
colors_[level::debug] = cyan;
|
colors_[level::debug] = cyan;
|
||||||
colors_[level::info] = white;
|
colors_[level::info] = bold;
|
||||||
colors_[level::notice] = bold + white;
|
colors_[level::warn] = yellow + bold;
|
||||||
colors_[level::warn] = bold + yellow;
|
colors_[level::err] = red + bold;
|
||||||
colors_[level::err] = red;
|
colors_[level::critical] = bold + on_red;
|
||||||
colors_[level::critical] = bold + red;
|
|
||||||
colors_[level::alert] = bold + white + on_red;
|
|
||||||
colors_[level::emerg] = bold + yellow + on_red;
|
|
||||||
colors_[level::off] = reset;
|
colors_[level::off] = reset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,12 +35,9 @@ public:
|
|||||||
_priorities[static_cast<int>(level::trace)] = LOG_DEBUG;
|
_priorities[static_cast<int>(level::trace)] = LOG_DEBUG;
|
||||||
_priorities[static_cast<int>(level::debug)] = LOG_DEBUG;
|
_priorities[static_cast<int>(level::debug)] = LOG_DEBUG;
|
||||||
_priorities[static_cast<int>(level::info)] = LOG_INFO;
|
_priorities[static_cast<int>(level::info)] = LOG_INFO;
|
||||||
_priorities[static_cast<int>(level::notice)] = LOG_NOTICE;
|
|
||||||
_priorities[static_cast<int>(level::warn)] = LOG_WARNING;
|
_priorities[static_cast<int>(level::warn)] = LOG_WARNING;
|
||||||
_priorities[static_cast<int>(level::err)] = LOG_ERR;
|
_priorities[static_cast<int>(level::err)] = LOG_ERR;
|
||||||
_priorities[static_cast<int>(level::critical)] = LOG_CRIT;
|
_priorities[static_cast<int>(level::critical)] = LOG_CRIT;
|
||||||
_priorities[static_cast<int>(level::alert)] = LOG_ALERT;
|
|
||||||
_priorities[static_cast<int>(level::emerg)] = LOG_EMERG;
|
|
||||||
_priorities[static_cast<int>(level::off)] = LOG_INFO;
|
_priorities[static_cast<int>(level::off)] = LOG_INFO;
|
||||||
|
|
||||||
//set ident to be program name if empty
|
//set ident to be program name if empty
|
||||||
@ -65,7 +62,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<int, 10> _priorities;
|
std::array<int, 7> _priorities;
|
||||||
//must store the ident because the man says openlog might use the pointer as is and not a string copy
|
//must store the ident because the man says openlog might use the pointer as is and not a string copy
|
||||||
const std::string _ident;
|
const std::string _ident;
|
||||||
|
|
||||||
|
@ -134,14 +134,15 @@ void drop_all();
|
|||||||
// SPDLOG_DEBUG(my_logger, "Some debug message {} {}", 1, 3.2);
|
// SPDLOG_DEBUG(my_logger, "Some debug message {} {}", 1, 3.2);
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#ifdef SPDLOG_TRACE_ON
|
#ifdef SPDLOG_TRACE_ON
|
||||||
#define SPDLOG_TRACE(logger, ...) logger->trace(__VA_ARGS__) << " (" << __FILE__ << " #" << __LINE__ <<")";
|
#define SPDLOG_TRACE(logger, ...) logger->trace(__FILE__ ## " line " ## SPDLOG_STR(__LINE__) ## ": " ## __VA_ARGS__);
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_TRACE(logger, ...)
|
#define SPDLOG_TRACE(logger, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SPDLOG_DEBUG_ON
|
#ifdef SPDLOG_DEBUG_ON
|
||||||
#define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__) << " (" << __FILE__ << " #" << __LINE__ <<")";
|
#define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_DEBUG(logger, ...)
|
#define SPDLOG_DEBUG(logger, ...)
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user