Skip to content

Commit

Permalink
wip1
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Dec 6, 2024
1 parent 166843f commit 8d49437
Show file tree
Hide file tree
Showing 47 changed files with 318 additions and 1,286 deletions.
17 changes: 5 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ find_package(Threads REQUIRED)
# Library sources
# ---------------------------------------------------------------------------------------
set(SPDLOG_HEADERS
"include/spdlog/async.h"
"include/spdlog/async_logger.h"
"include/spdlog/async_logger.h"
"include/spdlog/common.h"
"include/spdlog/formatter.h"
"include/spdlog/fwd.h"
Expand All @@ -160,9 +159,7 @@ set(SPDLOG_HEADERS
"include/spdlog/details/os.h"
"include/spdlog/details/periodic_worker.h"
"include/spdlog/details/context.h"
"include/spdlog/details/synchronous_factory.h"
"include/spdlog/details/thread_pool.h"
"include/spdlog/fmt/bin_to_hex.h"
"include/spdlog/fmt/bin_to_hex.h"
"include/spdlog/fmt/fmt.h"
"include/spdlog/sinks/android_sink.h"
"include/spdlog/sinks/base_sink.h"
Expand All @@ -189,8 +186,7 @@ set(SPDLOG_HEADERS
"include/spdlog/sinks/udp_sink.h")

set(SPDLOG_SRCS
"src/async_logger.cpp"
"src/common.cpp"
"src/common.cpp"
"src/logger.cpp"
"src/pattern_formatter.cpp"
"src/spdlog.cpp"
Expand All @@ -199,13 +195,10 @@ set(SPDLOG_SRCS
"src/details/log_msg.cpp"
"src/details/log_msg_buffer.cpp"
"src/details/context.cpp"
"src/details/thread_pool.cpp"
"src/sinks/base_sink.cpp"
"src/sinks/base_sink.cpp"
"src/sinks/basic_file_sink.cpp"
"src/sinks/rotating_file_sink.cpp"
"src/sinks/sink.cpp"
"src/sinks/stdout_color_sinks.cpp"
"src/sinks/stdout_sinks.cpp")
"src/sinks/stdout_sinks.cpp")

if(WIN32)
list(APPEND SPDLOG_SRCS
Expand Down
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,33 +245,11 @@ void callback_example()
#include "spdlog/sinks/basic_file_sink.h"
void async_example()
{
// default thread pool settings can be modified *before* creating the async logger:
// spdlog::init_thread_pool(8192, 1); // queue with 8k items and 1 backing thread.
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
// alternatively:
// auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");
// TODO
}

```

---
#### Asynchronous logger with multi sinks
```c++
#include "spdlog/async.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/rotating_file_sink.h"

void multi_sink_example2()
{
spdlog::init_thread_pool(8192, 1);
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt >();
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("mylog.txt", 1024*1024*10, 3);
std::vector<spdlog::sink_ptr> sinks {stdout_sink, rotating_sink};
auto logger = std::make_shared<spdlog::async_logger>("loggername", sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
spdlog::register_logger(logger);
}
```

---
#### User-defined types
```c++
Expand Down
50 changes: 26 additions & 24 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void replace_global_logger_example();
#include "spdlog/spdlog.h"
#include "spdlog/version.h"

using namespace spdlog::sinks;

int main(int, char *[]) {
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
spdlog::warn("Easy padding in numbers like {:08d}", 12);
Expand Down Expand Up @@ -84,50 +86,50 @@ int main(int, char *[]) {
// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed.
void stdout_logger_example() {
// Create color multithreading logger.
auto console = spdlog::stdout_color_mt("console");
auto console = spdlog::create<stdout_color_sink_mt>("console");
// or for stderr:
// auto console = spdlog::stderr_color_mt("error-logger");
//auto console = spdlog::create<stderr_color_sink_mt>("console");
}

#include "spdlog/sinks/basic_file_sink.h"
void basic_example() {
// Create basic file logger (not rotated).
auto my_logger = spdlog::basic_logger_mt("file_logger", "logs/basic-log.txt", true);
auto my_logger = spdlog::create<basic_file_sink_mt>("file_logger", "logs/basic-log.txt", true);
}

#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::create<rotating_file_sink_mt>("some_logger_name", "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::create<daily_file_format_sink_mt>("daily_logger", "logs/daily.txt", 2, 30);
}

#include "spdlog/sinks/callback_sink.h"
void callback_example() {
// Create the logger
auto logger = spdlog::callback_logger_mt("custom_callback_logger", [](const spdlog::details::log_msg & /*msg*/) {
auto logger = spdlog::create<callback_sink_mt>("custom_callback_logger", [](const spdlog::details::log_msg & /*msg*/) {
// do what you need to do with msg
});
}

#include "spdlog/async.h"
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");
// alternatively:
// auto async_file =
// spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger",
// "logs/async_log.txt");

for (int i = 1; i < 101; ++i) {
async_file->info("Async message #{}", i);
}
// TODO
// // 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");
// // alternatively:
// // auto async_file =
// // spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger",
// // "logs/async_log.txt");
//
// for (int i = 1; i < 101; ++i) {
// async_file->info("Async message #{}", i);
// }
}

// Log binary data as hex.
Expand Down Expand Up @@ -183,19 +185,19 @@ void stopwatch_example() {

#include "spdlog/sinks/udp_sink.h"
void udp_example() {
spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091);
auto my_logger = spdlog::udp_logger_mt("udplog", cfg);
udp_sink_config cfg("127.0.0.1", 11091);
auto my_logger = spdlog::create<udp_sink_mt>("udplog", cfg);
my_logger->set_level(spdlog::level::debug);
my_logger->info("hello world");
}

// A logger with multiple sinks (stdout and file) - each with a different format and log level.
void multi_sink_example() {
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto console_sink = std::make_shared<stdout_color_sink_mt>();
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<basic_file_sink_mt>("logs/multisink.txt", true);
file_sink->set_level(spdlog::level::trace);

spdlog::logger logger("multi_sink", {console_sink, file_sink});
Expand Down Expand Up @@ -231,7 +233,7 @@ void err_handler_example() {
#include "spdlog/sinks/syslog_sink.h"
void syslog_example() {
std::string ident = "spdlog-example";
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
auto syslog_logger = spdlog::create<syslog_sink_mt>("syslog", ident, 0);
syslog_logger->warn("This is warning that will end up in syslog.");
}
#endif
Expand Down Expand Up @@ -291,7 +293,7 @@ void replace_global_logger_example() {
// store the old logger so we don't break other examples.
auto old_logger = spdlog::global_logger();

auto new_logger = spdlog::basic_logger_mt("new_global_logger", "logs/new-default-log.txt", true);
auto new_logger = spdlog::create<basic_file_sink_mt>("new_global_logger", "logs/new-default-log.txt", true);
spdlog::set_global_logger(new_logger);
spdlog::set_level(spdlog::level::info);
spdlog::debug("This message should not be displayed!");
Expand Down
85 changes: 0 additions & 85 deletions include/spdlog/async.h

This file was deleted.

21 changes: 0 additions & 21 deletions include/spdlog/details/synchronous_factory.h

This file was deleted.

Loading

0 comments on commit 8d49437

Please sign in to comment.