mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
Fix build errors
This commit is contained in:
parent
a453bccff0
commit
19dc30567e
@ -109,21 +109,21 @@ void stdout_logger_example()
|
||||
void basic_example()
|
||||
{
|
||||
// Create basic file logger (not rotated).
|
||||
auto my_logger = spdlog::basic_logger_mt("file_logger", "logs/basic-log.txt");
|
||||
auto my_logger = spdlog::basic_logger_mt("file_logger", SPDLOG_FILENAME_T("logs/basic-log.txt"));
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
void rotating_example()
|
||||
{
|
||||
// Create a file rotating logger with 5mb size max and 3 rotated files.
|
||||
auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", SPDLOG_FILENAME_T("logs/rotating.txt"), 1048576 * 5, 3);
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
void daily_example()
|
||||
{
|
||||
// Create a daily logger - a new file is created every day on 2:30am.
|
||||
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||
auto daily_logger = spdlog::daily_logger_mt("daily_logger", SPDLOG_FILENAME_T("logs/daily.txt"), 2, 30);
|
||||
}
|
||||
|
||||
#include "spdlog/cfg/env.h"
|
||||
@ -143,7 +143,7 @@ void async_example()
|
||||
{
|
||||
// Default thread pool settings can be modified *before* creating the async logger:
|
||||
// spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread.
|
||||
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
|
||||
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", SPDLOG_FILENAME_T("logs/async_log.txt"));
|
||||
// alternatively:
|
||||
// auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");
|
||||
|
||||
@ -211,7 +211,7 @@ void multi_sink_example()
|
||||
console_sink->set_level(spdlog::level::warn);
|
||||
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
|
||||
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(SPDLOG_FILENAME_T("logs/multisink.txt"), true);
|
||||
file_sink->set_level(spdlog::level::trace);
|
||||
|
||||
spdlog::logger logger("multi_sink", {console_sink, file_sink});
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
#define TEST_FILENAME "test_logs/async_test.log"
|
||||
|
||||
TEST_CASE("basic async test ", "[async]")
|
||||
{
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
@ -149,7 +151,7 @@ TEST_CASE("to_file", "[async]")
|
||||
prepare_logdir();
|
||||
size_t messages = 1024;
|
||||
size_t tp_threads = 1;
|
||||
std::string filename = "test_logs/async_test.log";
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, tp_threads);
|
||||
@ -161,8 +163,8 @@ TEST_CASE("to_file", "[async]")
|
||||
}
|
||||
}
|
||||
|
||||
require_message_count(filename, messages);
|
||||
auto contents = file_contents(filename);
|
||||
require_message_count(TEST_FILENAME, messages);
|
||||
auto contents = file_contents(TEST_FILENAME);
|
||||
using spdlog::details::os::default_eol;
|
||||
REQUIRE(ends_with(contents, fmt::format("Hello message #1023{}", default_eol)));
|
||||
}
|
||||
@ -172,7 +174,7 @@ TEST_CASE("to_file multi-workers", "[async]")
|
||||
prepare_logdir();
|
||||
size_t messages = 1024 * 10;
|
||||
size_t tp_threads = 10;
|
||||
std::string filename = "test_logs/async_test.log";
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, tp_threads);
|
||||
@ -184,5 +186,5 @@ TEST_CASE("to_file multi-workers", "[async]")
|
||||
}
|
||||
}
|
||||
|
||||
require_message_count(filename, messages);
|
||||
require_message_count(TEST_FILENAME, messages);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
|
||||
|
||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||
spdlog::memory_buf_t buf;
|
||||
spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w));
|
||||
spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w), buf);
|
||||
auto filename = fmt::to_string(buf);
|
||||
#else
|
||||
auto filename = fmt::to_string(w);
|
||||
@ -65,7 +65,7 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
|
||||
|
||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||
spdlog::memory_buf_t buf;
|
||||
spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w));
|
||||
spdlog::details::os::wstr_to_utf8buf(fmt::to_string(w), buf);
|
||||
auto filename = fmt::to_string(buf);
|
||||
#else
|
||||
auto filename = fmt::to_string(w);
|
||||
|
@ -3,6 +3,8 @@
|
||||
*/
|
||||
#include "includes.h"
|
||||
|
||||
#define TEST_FILENAME "test_logs/file_helper_test.txt"
|
||||
|
||||
using spdlog::details::file_helper;
|
||||
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
@ -18,7 +20,7 @@ TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
|
||||
prepare_logdir();
|
||||
|
||||
file_helper helper;
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T("test_logs/file_helper_test.txt");
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
helper.open(target_filename);
|
||||
REQUIRE(helper.filename() == target_filename);
|
||||
}
|
||||
@ -26,7 +28,7 @@ TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
|
||||
TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T("test_logs/file_helper_test.txt");
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
size_t expected_size = 123;
|
||||
{
|
||||
file_helper helper;
|
||||
@ -34,13 +36,13 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
||||
write_with_helper(helper, expected_size);
|
||||
REQUIRE(static_cast<size_t>(helper.size()) == expected_size);
|
||||
}
|
||||
REQUIRE(get_filesize(target_filename) == expected_size);
|
||||
REQUIRE(get_filesize(TEST_FILENAME) == expected_size);
|
||||
}
|
||||
|
||||
TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T("test_logs/file_helper_test.txt");
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
file_helper helper;
|
||||
helper.open(target_filename);
|
||||
write_with_helper(helper, 12);
|
||||
@ -52,7 +54,7 @@ TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
||||
TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T("test_logs/file_helper_test.txt");
|
||||
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
size_t expected_size = 14;
|
||||
file_helper helper;
|
||||
helper.open(target_filename);
|
||||
|
@ -8,11 +8,13 @@
|
||||
#error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG"
|
||||
#endif
|
||||
|
||||
#define TEST_FILENAME "test_logs/simple_log"
|
||||
|
||||
TEST_CASE("debug and trace w/o format string", "[macros]]")
|
||||
{
|
||||
|
||||
prepare_logdir();
|
||||
std::string filename = "test_logs/simple_log";
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
|
||||
logger->set_pattern("%v");
|
||||
@ -23,8 +25,8 @@ TEST_CASE("debug and trace w/o format string", "[macros]]")
|
||||
logger->flush();
|
||||
|
||||
using spdlog::details::os::default_eol;
|
||||
REQUIRE(ends_with(file_contents(filename), fmt::format("Test message 2{}", default_eol)));
|
||||
REQUIRE(count_lines(filename) == 1);
|
||||
REQUIRE(ends_with(file_contents(TEST_FILENAME), fmt::format("Test message 2{}", default_eol)));
|
||||
REQUIRE(count_lines(TEST_FILENAME) == 1);
|
||||
|
||||
spdlog::set_default_logger(logger);
|
||||
|
||||
@ -32,8 +34,8 @@ TEST_CASE("debug and trace w/o format string", "[macros]]")
|
||||
SPDLOG_DEBUG("Test message {}", 4);
|
||||
logger->flush();
|
||||
|
||||
require_message_count(filename, 2);
|
||||
REQUIRE(ends_with(file_contents(filename), fmt::format("Test message 4{}", default_eol)));
|
||||
require_message_count(TEST_FILENAME, 2);
|
||||
REQUIRE(ends_with(file_contents(TEST_FILENAME), fmt::format("Test message 4{}", default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("disable param evaluation", "[macros]")
|
||||
|
@ -103,7 +103,7 @@ TEST_CASE("disable automatic registration", "[registry]")
|
||||
spdlog::set_level(log_level);
|
||||
// but disable automatic registration
|
||||
spdlog::set_automatic_registration(false);
|
||||
auto logger1 = spdlog::create<spdlog::sinks::daily_file_sink_st>(tested_logger_name, "filename", 11, 59);
|
||||
auto logger1 = spdlog::create<spdlog::sinks::daily_file_sink_st>(tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59);
|
||||
auto logger2 = spdlog::create_async<spdlog::sinks::stdout_color_sink_mt>(tested_logger_name2);
|
||||
// loggers should not be part of the registry
|
||||
REQUIRE_FALSE(spdlog::get(tested_logger_name));
|
||||
|
Loading…
Reference in New Issue
Block a user