mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-14 17:52:05 +08:00
Fix example
This commit is contained in:
parent
1c58ca4b5e
commit
f7c11f5d7e
@ -7,8 +7,6 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "spdlog/details/windows_include.h"
|
|
||||||
|
|
||||||
void load_levels_example();
|
void load_levels_example();
|
||||||
void stdout_logger_example();
|
void stdout_logger_example();
|
||||||
void basic_example();
|
void basic_example();
|
||||||
@ -34,26 +32,9 @@ void replace_default_logger_example();
|
|||||||
#include "spdlog/version.h"
|
#include "spdlog/version.h"
|
||||||
|
|
||||||
int main(int, char *[]) {
|
int main(int, char *[]) {
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
|
||||||
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
||||||
|
load_levels_example();
|
||||||
//spdlog::filename_t x = L"logs/hourlyעכעכ.txt";
|
SPDLOG_INFO("This message should be displayed..");
|
||||||
std::filesystem::path const x{L"\xd83d\x4000"};
|
|
||||||
try {
|
|
||||||
auto my_s = spdlog::details::os::filename_to_str(x);
|
|
||||||
spdlog::info("mystring: {}", my_s);
|
|
||||||
|
|
||||||
|
|
||||||
auto s = x.u8string();
|
|
||||||
spdlog::info("u8string: {}", s);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
SPDLOG_INFO("EXCEPTION {}", e.what());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
||||||
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
||||||
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||||
@ -133,12 +114,9 @@ void rotating_example() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "spdlog/sinks/daily_file_sink.h"
|
#include "spdlog/sinks/daily_file_sink.h"
|
||||||
#include "spdlog/sinks/hourly_file_sink.h"
|
|
||||||
void daily_example() {
|
void daily_example() {
|
||||||
using namespace spdlog::sinks;
|
|
||||||
// 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 = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||||
auto hourly_logger = spdlog::hourly_logger_mt("hourly_logger", L"logs/hourlyגבי.txt", 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "spdlog/sinks/callback_sink.h"
|
#include "spdlog/sinks/callback_sink.h"
|
||||||
@ -318,20 +296,16 @@ void custom_flags_example() {
|
|||||||
void file_events_example() {
|
void file_events_example() {
|
||||||
// pass the spdlog::file_event_handlers to file sinks for open/close log file notifications
|
// pass the spdlog::file_event_handlers to file sinks for open/close log file notifications
|
||||||
spdlog::file_event_handlers handlers;
|
spdlog::file_event_handlers handlers;
|
||||||
handlers.before_open = [](spdlog::filename_t filename) {
|
handlers.before_open = [](spdlog::filename_t filename) { spdlog::info("Before opening ", filename.u8string()); };
|
||||||
// spdlog::info("Before opening {}", filename);
|
|
||||||
};
|
|
||||||
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) {
|
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) {
|
||||||
// spdlog::info("After opening {}", filename);
|
spdlog::info("After opening {}", filename.u8string());
|
||||||
fputs("After opening\n", fstream);
|
fputs("After opening\n", fstream);
|
||||||
};
|
};
|
||||||
handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) {
|
handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) {
|
||||||
// spdlog::info("Before closing {}", filename);
|
spdlog::info("Before closing {}", filename.u8string());
|
||||||
fputs("Before closing\n", fstream);
|
fputs("Before closing\n", fstream);
|
||||||
};
|
};
|
||||||
handlers.after_close = [](spdlog::filename_t filename) {
|
handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename.u8string()); };
|
||||||
// spdlog::info("After closing {}", filename);
|
|
||||||
};
|
|
||||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt", true, handlers);
|
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt", true, handlers);
|
||||||
spdlog::logger my_logger("some_logger", file_sink);
|
spdlog::logger my_logger("some_logger", file_sink);
|
||||||
my_logger.info("Some log line");
|
my_logger.info("Some log line");
|
||||||
|
Loading…
Reference in New Issue
Block a user