fixed example

This commit is contained in:
gabime 2014-12-07 06:02:46 +02:00
parent 76436d07cc
commit 159165665d
2 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -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!";