mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 17:00:25 +08:00
astyle
This commit is contained in:
parent
d2a367fa7c
commit
3afabcd17e
@ -56,8 +56,8 @@ int main(int, char*[])
|
|||||||
|
|
||||||
// Create a daily logger - a new file is created every day on 2:30am
|
// Create a daily logger - a new file is created every day on 2:30am
|
||||||
auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily", 2, 30);
|
auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily", 2, 30);
|
||||||
// trigger flush if the log severity is error or higher
|
// trigger flush if the log severity is error or higher
|
||||||
daily_logger->flush_on(spd::level::err);
|
daily_logger->flush_on(spd::level::err);
|
||||||
daily_logger->info(123.44);
|
daily_logger->info(123.44);
|
||||||
|
|
||||||
// Customize msg format for all messages
|
// Customize msg format for all messages
|
||||||
|
@ -75,8 +75,8 @@ inline void spdlog::async_logger::_sink_it(details::log_msg& msg)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_async_log_helper->log(msg);
|
_async_log_helper->log(msg);
|
||||||
if (_should_flush_on(msg))
|
if (_should_flush_on(msg))
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
catch (const std::exception &ex)
|
catch (const std::exception &ex)
|
||||||
{
|
{
|
||||||
|
@ -283,6 +283,6 @@ inline void spdlog::logger::_default_err_handler(const std::string &msg)
|
|||||||
|
|
||||||
inline bool spdlog::logger::_should_flush_on(const details::log_msg &msg)
|
inline bool spdlog::logger::_should_flush_on(const details::log_msg &msg)
|
||||||
{
|
{
|
||||||
const auto flush_level = _flush_level.load(std::memory_order_relaxed);
|
const auto flush_level = _flush_level.load(std::memory_order_relaxed);
|
||||||
return (msg.level >= flush_level) && (msg.level != level::off);
|
return (msg.level >= flush_level) && (msg.level != level::off);
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ protected:
|
|||||||
// default error handler: print the error to stderr with the max rate of 1 message/minute
|
// default error handler: print the error to stderr with the max rate of 1 message/minute
|
||||||
virtual void _default_err_handler(const std::string &msg);
|
virtual void _default_err_handler(const std::string &msg);
|
||||||
|
|
||||||
// return true if the given message level should trigger a flush
|
// return true if the given message level should trigger a flush
|
||||||
bool _should_flush_on(const details::log_msg&);
|
bool _should_flush_on(const details::log_msg&);
|
||||||
|
|
||||||
const std::string _name;
|
const std::string _name;
|
||||||
std::vector<sink_ptr> _sinks;
|
std::vector<sink_ptr> _sinks;
|
||||||
|
@ -26,7 +26,7 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
|
|||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
std::string basename = "logs/rotating_log";
|
std::string basename = "logs/rotating_log";
|
||||||
auto logger = spdlog::rotating_logger_mt("logger", basename, 1024, 0);
|
auto logger = spdlog::rotating_logger_mt("logger", basename, 1024, 0);
|
||||||
logger->flush_on(spdlog::level::info);
|
logger->flush_on(spdlog::level::info);
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
logger->info("Test message {}", i);
|
logger->info("Test message {}", i);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ TEST_CASE("daily_logger", "[daily_logger]]")
|
|||||||
w.write("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.txt", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
w.write("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.txt", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||||
|
|
||||||
auto logger = spdlog::daily_logger_mt("logger", basename, 0, 0);
|
auto logger = spdlog::daily_logger_mt("logger", basename, 0, 0);
|
||||||
logger->flush_on(spdlog::level::info);
|
logger->flush_on(spdlog::level::info);
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
logger->info("Test message {}", i);
|
logger->info("Test message {}", i);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user