mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 17:00:25 +08:00
wip static-lib
This commit is contained in:
parent
5220ac4a9e
commit
d5c9bac3c7
@ -2,7 +2,6 @@
|
|||||||
// Copyright(c) 2015 Gabi Melman.
|
// Copyright(c) 2015 Gabi Melman.
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
|
||||||
// spdlog usage example
|
// spdlog usage example
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "spdlog/details/null_mutex.h"
|
#include "spdlog/details/null_mutex.h"
|
||||||
#include "spdlog/fmt/fmt.h"
|
#include "spdlog/fmt/fmt.h"
|
||||||
#include "spdlog/sinks/base_sink.h"
|
#include "spdlog/sinks/base_sink.h"
|
||||||
|
#include "spdlog/details/os.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "spdlog/details/console_globals.h"
|
#include "spdlog/details/console_globals.h"
|
||||||
#include "spdlog/details/null_mutex.h"
|
#include "spdlog/details/null_mutex.h"
|
||||||
|
#include "spdlog/details/pattern_formatter.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -100,5 +100,5 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::print_range_(const
|
|||||||
::WriteConsoleA(out_handle_, formatted.data() + start, size, nullptr, nullptr);
|
::WriteConsoleA(out_handle_, formatted.data() + start, size, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace sinks
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
@ -48,7 +48,6 @@ public:
|
|||||||
void set_pattern(const std::string &pattern) override final;
|
void set_pattern(const std::string &pattern) override final;
|
||||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
|
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||||
HANDLE out_handle_;
|
HANDLE out_handle_;
|
||||||
|
96
include/spdlog/spdlog-inl.h
Normal file
96
include/spdlog/spdlog-inl.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
// Copyright(c) 2015-present Gabi Melman & spdlog contributors.
|
||||||
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "spdlog/common.h"
|
||||||
|
#include "spdlog/details/pattern_formatter.h"
|
||||||
|
|
||||||
|
namespace spdlog {
|
||||||
|
|
||||||
|
SPDLOG_INLINE void initialize_logger(std::shared_ptr<logger> logger)
|
||||||
|
{
|
||||||
|
details::registry::instance().initialize_logger(std::move(logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE std::shared_ptr<logger> get(const std::string &name)
|
||||||
|
{
|
||||||
|
return details::registry::instance().get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void set_formatter(std::unique_ptr<spdlog::formatter> formatter)
|
||||||
|
{
|
||||||
|
details::registry::instance().set_formatter(std::move(formatter));
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type)
|
||||||
|
{
|
||||||
|
set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void set_level(level::level_enum log_level)
|
||||||
|
{
|
||||||
|
details::registry::instance().set_level(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void flush_on(level::level_enum log_level)
|
||||||
|
{
|
||||||
|
details::registry::instance().flush_on(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void flush_every(std::chrono::seconds interval)
|
||||||
|
{
|
||||||
|
details::registry::instance().flush_every(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg))
|
||||||
|
{
|
||||||
|
details::registry::instance().set_error_handler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void register_logger(std::shared_ptr<logger> logger)
|
||||||
|
{
|
||||||
|
details::registry::instance().register_logger(std::move(logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun)
|
||||||
|
{
|
||||||
|
details::registry::instance().apply_all(fun);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void drop(const std::string &name)
|
||||||
|
{
|
||||||
|
details::registry::instance().drop(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void drop_all()
|
||||||
|
{
|
||||||
|
details::registry::instance().drop_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void shutdown()
|
||||||
|
{
|
||||||
|
details::registry::instance().shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void set_automatic_registration(bool automatic_registation)
|
||||||
|
{
|
||||||
|
details::registry::instance().set_automatic_registration(automatic_registation);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE std::shared_ptr<spdlog::logger> default_logger()
|
||||||
|
{
|
||||||
|
return details::registry::instance().default_logger();
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE spdlog::logger *default_logger_raw()
|
||||||
|
{
|
||||||
|
return details::registry::instance().get_default_raw();
|
||||||
|
}
|
||||||
|
|
||||||
|
SPDLOG_INLINE void set_default_logger(std::shared_ptr<spdlog::logger> default_logger)
|
||||||
|
{
|
||||||
|
details::registry::instance().set_default_logger(std::move(default_logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace spdlog
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "spdlog/details/registry.h"
|
#include "spdlog/details/registry.h"
|
||||||
#include "spdlog/details/pattern_formatter.h"
|
|
||||||
#include "spdlog/logger.h"
|
#include "spdlog/logger.h"
|
||||||
#include "spdlog/version.h"
|
#include "spdlog/version.h"
|
||||||
|
|
||||||
@ -58,94 +57,52 @@ inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs
|
|||||||
// auto console_sink = std::make_shared<spdlog::sinks::stdout_sink_mt>();
|
// auto console_sink = std::make_shared<spdlog::sinks::stdout_sink_mt>();
|
||||||
// auto console_logger = std::make_shared<spdlog::logger>("console_logger", console_sink);
|
// auto console_logger = std::make_shared<spdlog::logger>("console_logger", console_sink);
|
||||||
// spdlog::initialize_logger(console_logger);
|
// spdlog::initialize_logger(console_logger);
|
||||||
inline void initialize_logger(std::shared_ptr<logger> logger)
|
void initialize_logger(std::shared_ptr<logger> logger);
|
||||||
{
|
|
||||||
details::registry::instance().initialize_logger(std::move(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return an existing logger or nullptr if a logger with such name doesn't
|
// Return an existing logger or nullptr if a logger with such name doesn't
|
||||||
// exist.
|
// exist.
|
||||||
// example: spdlog::get("my_logger")->info("hello {}", "world");
|
// example: spdlog::get("my_logger")->info("hello {}", "world");
|
||||||
inline std::shared_ptr<logger> get(const std::string &name)
|
std::shared_ptr<logger> get(const std::string &name);
|
||||||
{
|
|
||||||
return details::registry::instance().get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set global formatter. Each sink in each logger will get a clone of this object
|
// Set global formatter. Each sink in each logger will get a clone of this object
|
||||||
inline void set_formatter(std::unique_ptr<spdlog::formatter> formatter)
|
void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
|
||||||
{
|
|
||||||
details::registry::instance().set_formatter(std::move(formatter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set global format string.
|
// Set global format string.
|
||||||
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
|
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
|
||||||
inline void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local)
|
void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||||
{
|
|
||||||
set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set global logging level
|
// Set global logging level
|
||||||
inline void set_level(level::level_enum log_level)
|
void set_level(level::level_enum log_level);
|
||||||
{
|
|
||||||
details::registry::instance().set_level(log_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set global flush level
|
// Set global flush level
|
||||||
inline void flush_on(level::level_enum log_level)
|
void flush_on(level::level_enum log_level);
|
||||||
{
|
|
||||||
details::registry::instance().flush_on(log_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start/Restart a periodic flusher thread
|
// Start/Restart a periodic flusher thread
|
||||||
// Warning: Use only if all your loggers are thread safe!
|
// Warning: Use only if all your loggers are thread safe!
|
||||||
inline void flush_every(std::chrono::seconds interval)
|
void flush_every(std::chrono::seconds interval);
|
||||||
{
|
|
||||||
details::registry::instance().flush_every(interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set global error handler
|
// Set global error handler
|
||||||
inline void set_error_handler(void (*handler)(const std::string &msg))
|
void set_error_handler(void (*handler)(const std::string &msg));
|
||||||
{
|
|
||||||
details::registry::instance().set_error_handler(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register the given logger with the given name
|
// Register the given logger with the given name
|
||||||
inline void register_logger(std::shared_ptr<logger> logger)
|
void register_logger(std::shared_ptr<logger> logger);
|
||||||
{
|
|
||||||
details::registry::instance().register_logger(std::move(logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply a user defined function on all registered loggers
|
// Apply a user defined function on all registered loggers
|
||||||
// Example:
|
// Example:
|
||||||
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
|
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
|
||||||
inline void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun)
|
void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun);
|
||||||
{
|
|
||||||
details::registry::instance().apply_all(fun);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop the reference to the given logger
|
// Drop the reference to the given logger
|
||||||
inline void drop(const std::string &name)
|
void drop(const std::string &name);
|
||||||
{
|
|
||||||
details::registry::instance().drop(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop all references from the registry
|
// Drop all references from the registry
|
||||||
inline void drop_all()
|
void drop_all();
|
||||||
{
|
|
||||||
details::registry::instance().drop_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop any running threads started by spdlog and clean registry loggers
|
// stop any running threads started by spdlog and clean registry loggers
|
||||||
inline void shutdown()
|
void shutdown();
|
||||||
{
|
|
||||||
details::registry::instance().shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Automatic registration of loggers when using spdlog::create() or spdlog::create_async
|
// Automatic registration of loggers when using spdlog::create() or spdlog::create_async
|
||||||
inline void set_automatic_registration(bool automatic_registation)
|
void set_automatic_registration(bool automatic_registation);
|
||||||
{
|
|
||||||
details::registry::instance().set_automatic_registration(automatic_registation);
|
|
||||||
}
|
|
||||||
|
|
||||||
// API for using default logger (stdout_color_mt),
|
// API for using default logger (stdout_color_mt),
|
||||||
// e.g: spdlog::info("Message {}", 1);
|
// e.g: spdlog::info("Message {}", 1);
|
||||||
@ -162,20 +119,11 @@ inline void set_automatic_registration(bool automatic_registation)
|
|||||||
// set_default_logger() *should not* be used concurrently with the default API.
|
// set_default_logger() *should not* be used concurrently with the default API.
|
||||||
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
|
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
|
||||||
|
|
||||||
inline std::shared_ptr<spdlog::logger> default_logger()
|
std::shared_ptr<spdlog::logger> default_logger();
|
||||||
{
|
|
||||||
return details::registry::instance().default_logger();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline spdlog::logger *default_logger_raw()
|
spdlog::logger *default_logger_raw();
|
||||||
{
|
|
||||||
return details::registry::instance().get_default_raw();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_default_logger(std::shared_ptr<spdlog::logger> default_logger)
|
void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
|
||||||
{
|
|
||||||
details::registry::instance().set_default_logger(std::move(default_logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
inline void log(source_loc source, level::level_enum lvl, const char *fmt, const Args &... args)
|
inline void log(source_loc source, level::level_enum lvl, const char *fmt, const Args &... args)
|
||||||
@ -382,4 +330,8 @@ inline void critical(const wchar_t *fmt, const Args &... args)
|
|||||||
#define SPDLOG_CRITICAL(...) (void)0
|
#define SPDLOG_CRITICAL(...) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SPDLOG_HEADER_ONLY
|
||||||
|
#include "spdlog-inl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SPDLOG_H
|
#endif // SPDLOG_H
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "spdlog/spdlog-inl.h"
|
||||||
|
|
||||||
#include "spdlog/async.h"
|
#include "spdlog/async.h"
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user