mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
wip lite
This commit is contained in:
112
lite/spdlite.h
112
lite/spdlite.h
@@ -42,13 +42,15 @@ enum class level
|
||||
class logger
|
||||
{
|
||||
public:
|
||||
explicit logger(std::shared_ptr<spdlog::logger> impl);
|
||||
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>
|
||||
@@ -65,26 +67,28 @@ public:
|
||||
|
||||
// log string view
|
||||
void log(spdlite::level lvl, const string_view_t &sv);
|
||||
|
||||
// log using printf format
|
||||
void log_printf(spdlite::level lvl, const char *format, va_list args);
|
||||
|
||||
|
||||
//
|
||||
// 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...);
|
||||
}
|
||||
|
||||
void trace_printf(const char *format, ...);
|
||||
|
||||
|
||||
//
|
||||
// debug
|
||||
//
|
||||
@@ -93,72 +97,101 @@ public:
|
||||
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...);
|
||||
}
|
||||
|
||||
void debug_printf(const char *format, ...);
|
||||
|
||||
// info
|
||||
|
||||
// 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...);
|
||||
}
|
||||
|
||||
void info_printf(const char *format, ...);
|
||||
|
||||
// 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...);
|
||||
}
|
||||
|
||||
void warn_printf(const char *format, ...);
|
||||
|
||||
|
||||
// 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...);
|
||||
}
|
||||
|
||||
void error_printf(const char *format, ...);
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
@@ -167,56 +200,69 @@ public:
|
||||
// flush
|
||||
void flush();
|
||||
void flush_on(spdlite::level log_level);
|
||||
|
||||
//clone with new name
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
//
|
||||
// spdlite namespace functions - forward the calls to the default_logger.
|
||||
//
|
||||
spdlite::logger &default_logger();
|
||||
|
||||
template<typename... Args>
|
||||
void trace(const char *fmt, const Args &... args)
|
||||
inline void trace(const char *fmt, const Args &... args)
|
||||
{
|
||||
default_logger().trace(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(const char *fmt, const Args &... args)
|
||||
inline void debug(const char *fmt, const Args &... args)
|
||||
{
|
||||
default_logger().debug(fmt, args...);
|
||||
}
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
void info(const char *fmt, const Args &... args)
|
||||
inline void info(const char *fmt, const Args &... args)
|
||||
{
|
||||
default_logger().info(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(const char *fmt, const Args &... args)
|
||||
inline void warn(const char *fmt, const Args &... args)
|
||||
{
|
||||
default_logger().warn(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(const char *fmt, const Args &... args)
|
||||
inline void error(const char *fmt, const Args &... args)
|
||||
{
|
||||
default_logger().error(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(const char *fmt, const Args &... args)
|
||||
inline void critical(const char *fmt, const Args &... args)
|
||||
{
|
||||
default_logger().critical(fmt, args...);
|
||||
}
|
||||
|
||||
// user implemented factory to create lite logger
|
||||
// implement it in a seperated and dedicated compilation unit for fast compiles.
|
||||
logger create_logger(void *ctx = nullptr);
|
||||
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, ...);
|
||||
|
||||
} // 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);
|
||||
|
Reference in New Issue
Block a user