mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
fixed example
This commit is contained in:
parent
76436d07cc
commit
159165665d
@ -4,7 +4,7 @@ CXX_RELEASE_FLAGS = -O3 -flto
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
|
||||
all: bench
|
||||
all: example bench
|
||||
debug: example-debug bench-debug
|
||||
|
||||
example: example.cpp
|
||||
|
@ -26,8 +26,8 @@
|
||||
// spdlog usage example
|
||||
//
|
||||
#include <iostream>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/details/format.h"
|
||||
#include "spdlog/spdlog.h"ls
|
||||
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
@ -36,8 +36,6 @@ int main(int, char* [])
|
||||
|
||||
try
|
||||
{
|
||||
fmt::print("Hello man {} {:1f}\n", 1, 2.2);
|
||||
return 0;
|
||||
std::string filename = "logs/spdlog_example";
|
||||
// Set log level to all loggers to DEBUG and above
|
||||
spd::set_level(spd::level::DEBUG);
|
||||
@ -46,9 +44,19 @@ int main(int, char* [])
|
||||
//Create console, multithreaded logger
|
||||
auto console = spd::stdout_logger_mt("console");
|
||||
console->info("Welcome to spdlog!") ;
|
||||
console->info("An info message example", "...", 1, 2, 3.5);
|
||||
console->info("An info message example {}..", 1);
|
||||
console->info() << "Streams are supported too " << 1;
|
||||
|
||||
|
||||
console->info("Easy padding in numbers like {:08d}", 12);
|
||||
console->info("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
console->info("Support for floats {:03.2f}", 1.23456);
|
||||
console->info("Positional args are {1} {0}..", "too", "supported");
|
||||
|
||||
console->info("{:<30}", "left aligned");
|
||||
console->info("{:>30}", "right aligned");
|
||||
console->info("{:^30}", "centered");
|
||||
|
||||
//Create a file rotating logger with 5mb size max and 3 rotated files
|
||||
auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3);
|
||||
file_logger->info("Log file message number", 1);
|
||||
@ -65,7 +73,7 @@ int main(int, char* [])
|
||||
// Asynchronous logging is easy..
|
||||
// Just call spdlog::set_async_mode(max_q_size) and all created loggers from now on will be asynchronous..
|
||||
//
|
||||
size_t max_q_size = 100000;
|
||||
size_t max_q_size = 1048576;
|
||||
spdlog::set_async_mode(max_q_size);
|
||||
auto async_file= spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
|
||||
async_file->info() << "This is async log.." << "Should be very fast!";
|
||||
|
Loading…
Reference in New Issue
Block a user