From 6c30da159125ad0984efa26c04c9117fc77ba402 Mon Sep 17 00:00:00 2001 From: Matan Nassau Date: Wed, 21 Jan 2015 01:41:06 -0500 Subject: [PATCH] fix broken examples in run from arbitrary dirs examples work fine when run from example/, as in $ cd example/ $ ./example but otherwise break: $ cd $ ~/path/to/spdlog/example/bench the above would fail on trying to open the logs/somefile for writing if the logs directory doesn't exist in the current directory. let's not assume there is a logs/ directory and just write our logs in the current directory. we can suffix the logs with .log so they're easy to find in .gitignore for cleanup. and with that, we don't need the logs direcory, or the .gitignore inside it that keeps it hanging. --- .gitignore | 2 +- example/bench.cpp | 10 +++++----- example/example.cpp | 4 ++-- example/logs/.gitignore | 4 ---- 4 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 example/logs/.gitignore diff --git a/.gitignore b/.gitignore index 6c04147d..a4ce2d37 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,4 @@ example/* !example/makefile !example/makefile.clang - +*.log diff --git a/example/bench.cpp b/example/bench.cpp index b2f41b12..84c8fbce 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -69,9 +69,9 @@ int main(int argc, char* argv[]) cout << "Single thread, " << format(howmany) << " iterations, auto flush=" << auto_flush << endl; cout << "*******************************************************************************\n"; - auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files, auto_flush); + auto rotating_st = spdlog::rotating_logger_st("rotating_st", "rotating_st.log", file_size, rotating_files, auto_flush); bench(howmany, rotating_st); - auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st", auto_flush); + auto daily_st = spdlog::daily_logger_st("daily_st", "daily_st.log", auto_flush); bench(howmany, daily_st); bench(howmany, spdlog::create("null_st")); @@ -79,11 +79,11 @@ int main(int argc, char* argv[]) cout << threads << " threads sharing same logger, " << format(howmany) << " iterations, auto_flush=" << auto_flush << endl; cout << "*******************************************************************************\n"; - auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt", file_size, rotating_files, auto_flush); + auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "rotating_mt.log", file_size, rotating_files, auto_flush); bench_mt(howmany, rotating_mt, threads); - auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt", auto_flush); + auto daily_mt = spdlog::daily_logger_mt("daily_mt", "daily_mt.log", auto_flush); bench_mt(howmany, daily_mt, threads); bench(howmany, spdlog::create("null_mt")); @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) for(int i = 0; i < 3; ++i) { - auto as = spdlog::daily_logger_st("as", "logs/daily_async", auto_flush); + auto as = spdlog::daily_logger_st("as", "daily_async.log", auto_flush); bench_mt(howmany, as, threads); spdlog::drop("as"); } diff --git a/example/example.cpp b/example/example.cpp index 312ee57f..9a4f2897 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -53,7 +53,7 @@ int main(int, char* []) 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", "logs/mylogfile", 1048576 * 5, 3); + auto file_logger = spd::rotating_logger_mt("file_logger", "mylogfile.log", 1048576 * 5, 3); file_logger->set_level(spd::level::info); for(int i = 0; i < 10; ++i) file_logger->info("{} * {} equals {:>10}", i, i, i*i); @@ -71,7 +71,7 @@ int main(int, char* []) // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous.. size_t q_size = 1048576; //queue size must be power of 2 spdlog::set_async_mode(q_size); - auto async_file= spd::daily_logger_st("async_file_logger", "logs/async_log.txt"); + auto async_file= spd::daily_logger_st("async_file_logger", "async_log.log"); async_file->info() << "This is async log.." << "Should be very fast!"; // syslog example. linux only.. diff --git a/example/logs/.gitignore b/example/logs/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/example/logs/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore