From 159165665d97b980ee70cce4456b775ea394f4bf Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 7 Dec 2014 06:02:46 +0200 Subject: [PATCH] fixed example --- example/Makefile | 2 +- example/example.cpp | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/example/Makefile b/example/Makefile index 746c7a9e..4208786a 100644 --- a/example/Makefile +++ b/example/Makefile @@ -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 diff --git a/example/example.cpp b/example/example.cpp index 4e464107..6acc94ba 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -26,8 +26,8 @@ // spdlog usage example // #include -#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!";