diff --git a/README.md b/README.md index 2a2cbe42..cc5af44b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,78 @@ +# spdlog-emoji ! + +It's an emoji version of [spdlog](https://github.com/gabime/spdlog)! Plus some new levels of logging. + +## What's difference +#### Why not enjoy some emojis! +WHO WANTS A LOG LIKE: +`[info] This is an info` +BUT NOT: +`[💬] This is an info` +? + +#### (New) Log levels and emojis +``` +TRACE 🐾 +DEBUG 🔧 +INFO 📢 +TIMING ⏰ +FUNNY 🤣 +WARN 🤔 * +JOKER 🤡 +GHOST 👻 +SUCCESS 🎉 +ERROR 🚨 +FINISH ✅ +CRITICAL ❌ +OFF O (yes, this is not an emoji since it's never used by users) +``` +\* I tried to use ⚠️, but it will be rendered by some default fonts, such as Menlo on MacOS, and it looks like `⚠️`. Since it is 21th Century now, The last one is totally unacceptable. + +#### Usage +Use it just like spdlog, and you have more choices: +``` +some_logger->trace("This is Trace"); +some_logger->debug("This is Debug"); +some_logger->info("This is Info"); +some_logger->timing("This is Timing"); +some_logger->funny("This is Funny"); +some_logger->warn("This is Warn"); +some_logger->joker("This is Joker"); +some_logger->ghost("This is Ghost"); +some_logger->success("This is Success"); +some_logger->error("This is Error"); +some_logger->finish("This is Finish"); +some_logger->critical("This is Critical"); +``` + +Here are what you got: + +``` +[2024-10-15 18:24:57.617] [some_logger_name] [🐾] This is Trace +[2024-10-15 18:24:57.617] [some_logger_name] [🔧] This is Debug +[2024-10-15 18:24:57.617] [some_logger_name] [💬] This is Info +[2024-10-15 18:24:57.617] [some_logger_name] [⏰] This is Timing +[2024-10-15 18:24:57.617] [some_logger_name] [🤣] This is Funny +[2024-10-15 18:24:57.617] [some_logger_name] [🤔] This is Warn +[2024-10-15 18:24:57.617] [some_logger_name] [🤡] This is Joker +[2024-10-15 18:24:57.617] [some_logger_name] [👻] This is Ghost +[2024-10-15 18:24:57.617] [some_logger_name] [🎉] This is Success +[2024-10-15 18:24:57.617] [some_logger_name] [🚨] This is Error +[2024-10-15 18:24:57.617] [some_logger_name] [✅] This is Finish +[2024-10-15 18:24:57.617] [some_logger_name] [❌] This is Critical + +``` + + +Tips: If you are using logging format that truncates the log_level_name, be careful, since emojis don't have a uniform string length and your truncation could result in weird output. + +----- + +Thanks to spdlog for its clean and tidy design and implementation, making this change very easy. + +Following is the README of spdlog: + +----- # spdlog Very fast, header-only/compiled, C++ logging library. [![ci](https://github.com/gabime/spdlog/actions/workflows/ci.yml/badge.svg)](https://github.com/gabime/spdlog/actions/workflows/ci.yml)  [![Build status](https://ci.appveyor.com/api/projects/status/d2jnxclg20vd0o50?svg=true&branch=v1.x)](https://ci.appveyor.com/project/gabime/spdlog) [![Release](https://img.shields.io/github/release/gabime/spdlog.svg)](https://github.com/gabime/spdlog/releases/latest) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index aca483c2..71ba677e 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -231,10 +231,17 @@ using level_t = std::atomic; #define SPDLOG_LEVEL_TRACE 0 #define SPDLOG_LEVEL_DEBUG 1 #define SPDLOG_LEVEL_INFO 2 -#define SPDLOG_LEVEL_WARN 3 -#define SPDLOG_LEVEL_ERROR 4 -#define SPDLOG_LEVEL_CRITICAL 5 -#define SPDLOG_LEVEL_OFF 6 +#define SPDLOG_LEVEL_TIMING 3 +#define SPDLOG_LEVEL_FUNNY 4 +#define SPDLOG_LEVEL_WARN 5 +#define SPDLOG_LEVEL_JOKER 6 +#define SPDLOG_LEVEL_GHOST 7 +#define SPDLOG_LEVEL_SUCCESS 8 +#define SPDLOG_LEVEL_ERROR 9 +#define SPDLOG_LEVEL_FINISH 10 +#define SPDLOG_LEVEL_CRITICAL 11 +#define SPDLOG_LEVEL_OFF 12 + #if !defined(SPDLOG_ACTIVE_LEVEL) #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO @@ -246,34 +253,56 @@ enum level_enum : int { trace = SPDLOG_LEVEL_TRACE, debug = SPDLOG_LEVEL_DEBUG, info = SPDLOG_LEVEL_INFO, + timing = SPDLOG_LEVEL_TIMING, + funny = SPDLOG_LEVEL_FUNNY, warn = SPDLOG_LEVEL_WARN, + joker = SPDLOG_LEVEL_JOKER, + ghost = SPDLOG_LEVEL_GHOST, + success = SPDLOG_LEVEL_SUCCESS, err = SPDLOG_LEVEL_ERROR, + finish = SPDLOG_LEVEL_FINISH, critical = SPDLOG_LEVEL_CRITICAL, off = SPDLOG_LEVEL_OFF, n_levels }; -#define SPDLOG_LEVEL_NAME_TRACE spdlog::string_view_t("trace", 5) -#define SPDLOG_LEVEL_NAME_DEBUG spdlog::string_view_t("debug", 5) -#define SPDLOG_LEVEL_NAME_INFO spdlog::string_view_t("info", 4) -#define SPDLOG_LEVEL_NAME_WARNING spdlog::string_view_t("warning", 7) -#define SPDLOG_LEVEL_NAME_ERROR spdlog::string_view_t("error", 5) -#define SPDLOG_LEVEL_NAME_CRITICAL spdlog::string_view_t("critical", 8) +#define SPDLOG_LEVEL_NAME_TRACE spdlog::string_view_t("🐾", sizeof("🐾")-1) +#define SPDLOG_LEVEL_NAME_DEBUG spdlog::string_view_t("🔧", sizeof("🔧")-1) // 🛠️ is kind of too dark in dark theme +#define SPDLOG_LEVEL_NAME_INFO spdlog::string_view_t("💬", sizeof("💬")-1) +#define SPDLOG_LEVEL_NAME_TIMING spdlog::string_view_t("⏰", sizeof("⏰")-1) +#define SPDLOG_LEVEL_NAME_FUNNY spdlog::string_view_t("🤣", sizeof("🤣")-1) +#define SPDLOG_LEVEL_NAME_WARNING spdlog::string_view_t("🤔", sizeof("🤔")-1) // ⚠️ will be rendered wrong! +#define SPDLOG_LEVEL_NAME_JOKER spdlog::string_view_t("🤡", sizeof("🤡")-1) +#define SPDLOG_LEVEL_NAME_GHOST spdlog::string_view_t("👻", sizeof("👻")-1) +#define SPDLOG_LEVEL_NAME_SUCCESS spdlog::string_view_t("🎉", sizeof("🎉")-1) +#define SPDLOG_LEVEL_NAME_ERROR spdlog::string_view_t("🚨", sizeof("🚨")-1) +#define SPDLOG_LEVEL_NAME_FINISH spdlog::string_view_t("✅", sizeof("✅")-1) +#define SPDLOG_LEVEL_NAME_CRITICAL spdlog::string_view_t("❌", sizeof("❌")-1) #define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t("off", 3) #if !defined(SPDLOG_LEVEL_NAMES) #define SPDLOG_LEVEL_NAMES \ { \ - SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, \ - SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, \ - SPDLOG_LEVEL_NAME_OFF \ + SPDLOG_LEVEL_NAME_TRACE, \ + SPDLOG_LEVEL_NAME_DEBUG, \ + SPDLOG_LEVEL_NAME_INFO, \ + SPDLOG_LEVEL_NAME_TIMING, \ + SPDLOG_LEVEL_NAME_FUNNY, \ + SPDLOG_LEVEL_NAME_WARNING, \ + SPDLOG_LEVEL_NAME_JOKER, \ + SPDLOG_LEVEL_NAME_GHOST, \ + SPDLOG_LEVEL_NAME_SUCCESS, \ + SPDLOG_LEVEL_NAME_ERROR, \ + SPDLOG_LEVEL_NAME_FINISH, \ + SPDLOG_LEVEL_NAME_CRITICAL, \ + SPDLOG_LEVEL_NAME_OFF \ } #endif #if !defined(SPDLOG_SHORT_LEVEL_NAMES) #define SPDLOG_SHORT_LEVEL_NAMES \ - { "T", "D", "I", "W", "E", "C", "O" } + { "🐾", "🔧", "💬", "⏰", "🤣", "🤔", "🤡", "👻", "🎉", "🚨", "✅", "❌", "O" } #endif SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index f49bdc00..94466ee8 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -17,6 +17,7 @@ #include #include #include +#include "common.h" #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifndef _WIN32 @@ -140,16 +141,45 @@ class SPDLOG_API logger { log(level::info, fmt, std::forward(args)...); } + template + void timing(format_string_t fmt, Args &&...args) { + log(level::timing, fmt, std::forward(args)...); + } + + template + void funny(format_string_t fmt, Args &&...args) { + log(level::funny, fmt, std::forward(args)...); + } + template void warn(format_string_t fmt, Args &&...args) { log(level::warn, fmt, std::forward(args)...); } + template + void joker(format_string_t fmt, Args &&...args) { + log(level::joker, fmt, std::forward(args)...); + } + + template + void ghost(format_string_t fmt, Args &&...args) { + log(level::ghost, fmt, std::forward(args)...); + } + + template + void success(format_string_t fmt, Args &&...args) { + log(level::success, fmt, std::forward(args)...); + } template void error(format_string_t fmt, Args &&...args) { log(level::err, fmt, std::forward(args)...); } + template + void finish(format_string_t fmt, Args &&...args) { + log(level::finish, fmt, std::forward(args)...); + } + template void critical(format_string_t fmt, Args &&...args) { log(level::critical, fmt, std::forward(args)...); @@ -212,16 +242,46 @@ class SPDLOG_API logger { log(level::info, fmt, std::forward(args)...); } + template + void timing(wformat_string_t fmt, Args &&...args) { + log(level::timing, fmt, std::forward(args)...); + } + + template + void funny(wformat_string_t fmt, Args &&...args) { + log(level::funny, fmt, std::forward(args)...); + } + template void warn(wformat_string_t fmt, Args &&...args) { log(level::warn, fmt, std::forward(args)...); } + template + void joker(wformat_string_t fmt, Args &&...args) { + log(level::joker, fmt, std::forward(args)...); + } + + template + void ghost(wformat_string_t fmt, Args &&...args) { + log(level::ghost, fmt, std::forward(args)...); + } + + template + void success(wformat_string_t fmt, Args &&...args) { + log(level::success, fmt, std::forward(args)...); + } + template void error(wformat_string_t fmt, Args &&...args) { log(level::err, fmt, std::forward(args)...); } + template + void finish(wformat_string_t fmt, Args &&...args) { + log(level::finish, fmt, std::forward(args)...); + } + template void critical(wformat_string_t fmt, Args &&...args) { log(level::critical, fmt, std::forward(args)...); @@ -243,16 +303,46 @@ class SPDLOG_API logger { log(level::info, msg); } + template + void timing(const T &msg) { + log(level::timing, msg); + } + + template + void funny(const T &msg) { + log(level::funny, msg); + } + template void warn(const T &msg) { log(level::warn, msg); } + template + void joker(const T &msg) { + log(level::joker, msg); + } + + template + void ghost(const T &msg) { + log(level::ghost, msg); + } + + template + void success(const T &msg) { + log(level::success, msg); + } + template void error(const T &msg) { log(level::err, msg); } + template + void finish(const T &msg) { + log(level::finish, msg); + } + template void critical(const T &msg) { log(level::critical, msg); diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index a8afbcec..990bd3db 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -168,16 +168,46 @@ inline void info(format_string_t fmt, Args &&...args) { default_logger_raw()->info(fmt, std::forward(args)...); } +template +inline void timing(format_string_t fmt, Args &&...args) { + default_logger_raw()->timing(fmt, std::forward(args)...); +} + +template +inline void funny(format_string_t fmt, Args &&...args) { + default_logger_raw()->funny(fmt, std::forward(args)...); +} + template inline void warn(format_string_t fmt, Args &&...args) { default_logger_raw()->warn(fmt, std::forward(args)...); } +template +inline void joker(format_string_t fmt, Args &&...args) { + default_logger_raw()->joker(fmt, std::forward(args)...); +} + +template +inline void ghost(format_string_t fmt, Args &&...args) { + default_logger_raw()->ghost(fmt, std::forward(args)...); +} + +template +inline void success(format_string_t fmt, Args &&...args) { + default_logger_raw()->success(fmt, std::forward(args)...); +} + template inline void error(format_string_t fmt, Args &&...args) { default_logger_raw()->error(fmt, std::forward(args)...); } +template +inline void finish(format_string_t fmt, Args &&...args) { + default_logger_raw()->finish(fmt, std::forward(args)...); +} + template inline void critical(format_string_t fmt, Args &&...args) { default_logger_raw()->critical(fmt, std::forward(args)...); @@ -208,7 +238,7 @@ inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&... } template -inline void trace(wformat_string_t fmt, Args &&...args) { +inline void trace(format_string_t fmt, Args &&...args) { default_logger_raw()->trace(fmt, std::forward(args)...); } @@ -222,16 +252,46 @@ inline void info(wformat_string_t fmt, Args &&...args) { default_logger_raw()->info(fmt, std::forward(args)...); } +template +inline void timing(wformat_string_t fmt, Args &&...args) { + default_logger_raw()->timing(fmt, std::forward(args)...); +} + +template +inline void funny(wformat_string_t fmt, Args &&...args) { + default_logger_raw()->funny(fmt, std::forward(args)...); +} + template inline void warn(wformat_string_t fmt, Args &&...args) { default_logger_raw()->warn(fmt, std::forward(args)...); } +template +inline void joker(wformat_string_t fmt, Args &&...args) { + default_logger_raw()->joker(fmt, std::forward(args)...); +} + +template +inline void ghost(wformat_string_t fmt, Args &&...args) { + default_logger_raw()->ghost(fmt, std::forward(args)...); +} + +template +inline void success(wformat_string_t fmt, Args &&...args) { + default_logger_raw()->success(fmt, std::forward(args)...); +} + template inline void error(wformat_string_t fmt, Args &&...args) { default_logger_raw()->error(fmt, std::forward(args)...); } +template +inline void finish(wformat_string_t fmt, Args &&...args) { + default_logger_raw()->finish(fmt, std::forward(args)...); +} + template inline void critical(wformat_string_t fmt, Args &&...args) { default_logger_raw()->critical(fmt, std::forward(args)...); @@ -253,16 +313,46 @@ inline void info(const T &msg) { default_logger_raw()->info(msg); } +template +inline void timing(const T &msg) { + default_logger_raw()->timing(msg); +} + +template +inline void funny(const T &msg) { + default_logger_raw()->funny(msg); +} + template inline void warn(const T &msg) { default_logger_raw()->warn(msg); } +template +inline void joker(const T &msg) { + default_logger_raw()->joker(msg); +} + +template +inline void ghost(const T &msg) { + default_logger_raw()->ghost(msg); +} + +template +inline void success(const T &msg) { + default_logger_raw()->success(msg); +} + template inline void error(const T &msg) { default_logger_raw()->error(msg); } +template +inline void finish(const T &msg) { + default_logger_raw()->finish(msg); +} + template inline void critical(const T &msg) { default_logger_raw()->critical(msg); @@ -318,6 +408,24 @@ inline void critical(const T &msg) { #define SPDLOG_INFO(...) (void)0 #endif +#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TIMING + #define SPDLOG_LOGGER_TIMING(logger, ...) \ + SPDLOG_LOGGER_CALL(logger, spdlog::level::timing, __VA_ARGS__) + #define SPDLOG_TIMING(...) SPDLOG_LOGGER_TIMING(spdlog::default_logger_raw(), __VA_ARGS__) +#else + #define SPDLOG_LOGGER_TIMING(logger, ...) (void)0 + #define SPDLOG_TIMING(...) (void)0 +#endif + +#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_FUNNY + #define SPDLOG_LOGGER_FUNNY(logger, ...) \ + SPDLOG_LOGGER_CALL(logger, spdlog::level::funny, __VA_ARGS__) + #define SPDLOG_FUNNY(...) SPDLOG_LOGGER_FUNNY(spdlog::default_logger_raw(), __VA_ARGS__) +#else + #define SPDLOG_LOGGER_FUNNY(logger, ...) (void)0 + #define SPDLOG_FUNNY(...) (void)0 +#endif + #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN #define SPDLOG_LOGGER_WARN(logger, ...) \ SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) @@ -327,6 +435,33 @@ inline void critical(const T &msg) { #define SPDLOG_WARN(...) (void)0 #endif +#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_JOKER + #define SPDLOG_LOGGER_JOKER(logger, ...) \ + SPDLOG_LOGGER_CALL(logger, spdlog::level::joker, __VA_ARGS__) + #define SPDLOG_JOKER(...) SPDLOG_LOGGER_JOKER(spdlog::default_logger_raw(), __VA_ARGS__) +#else + #define SPDLOG_LOGGER_JOKER(logger, ...) (void)0 + #define SPDLOG_JOKER(...) (void)0 +#endif + +#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_GHOST + #define SPDLOG_LOGGER_GHOST(logger, ...) \ + SPDLOG_LOGGER_CALL(logger, spdlog::level::ghost, __VA_ARGS__) + #define SPDLOG_GHOST(...) SPDLOG_LOGGER_GHOST(spdlog::default_logger_raw(), __VA_ARGS__) +#else + #define SPDLOG_LOGGER_GHOST(logger, ...) (void)0 + #define SPDLOG_GHOST(...) (void)0 +#endif + +#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_SUCCESS + #define SPDLOG_LOGGER_SUCCESS(logger, ...) \ + SPDLOG_LOGGER_CALL(logger, spdlog::level::success, __VA_ARGS__) + #define SPDLOG_SUCCESS(...) SPDLOG_LOGGER_SUCCESS(spdlog::default_logger_raw(), __VA_ARGS__) +#else + #define SPDLOG_LOGGER_SUCCESS(logger, ...) (void)0 + #define SPDLOG_SUCCESS(...) (void)0 +#endif + #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR #define SPDLOG_LOGGER_ERROR(logger, ...) \ SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) @@ -336,6 +471,15 @@ inline void critical(const T &msg) { #define SPDLOG_ERROR(...) (void)0 #endif +#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_FINISH + #define SPDLOG_LOGGER_FINISH(logger, ...) \ + SPDLOG_LOGGER_CALL(logger, spdlog::level::finish, __VA_ARGS__) + #define SPDLOG_FINISH(...) SPDLOG_LOGGER_FINISH(spdlog::default_logger_raw(), __VA_ARGS__) +#else + #define SPDLOG_LOGGER_FINISH(logger, ...) (void)0 + #define SPDLOG_FINISH(...) (void)0 +#endif + #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL #define SPDLOG_LOGGER_CRITICAL(logger, ...) \ SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)