diff --git a/README.md b/README.md index c9e5df8f..1f562e14 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,13 @@ int main(int, char* []) console->debug("This message shold not be displayed!"); console->set_level(spd::level::debug); // Set specific logger's log level console->debug("Now it should.."); + + // + // Create a basic file logger (multithreaded, use "file_logger_st" for single threaded logger) + // + auto simple_logger = spd::file_logger_mt("basic_logger", "logs/simple.txt"); + simple_logger->info("Some log message"); + // // Create a file rotating logger with 5mb size max and 3 rotated files diff --git a/example/example.cpp b/example/example.cpp index b3d6c439..fa34254f 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -43,6 +43,11 @@ int main(int, char*[]) console->set_level(spd::level::debug); // Set specific logger's log level console->debug("This message shold be displayed.."); + // Create basic file logger (not rotated) + auto simple_logger = spd::basic_logger_mt("basic_logger", "logs/simple.txt"); + simple_logger->info("Some log message"); + + // 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); for (int i = 0; i < 10; ++i) diff --git a/example/example.vcxproj b/example/example.vcxproj index b7988fc9..3356baa3 100644 --- a/example/example.vcxproj +++ b/example/example.vcxproj @@ -22,13 +22,13 @@ Application true - v140 + v120 Unicode Application false - v140 + v120 true Unicode diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index bfc56717..59227e9b 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -35,6 +35,17 @@ inline void spdlog::drop(const std::string &name) details::registry::instance().drop(name); } +// Create multi/single threaded simple file logger +inline std::shared_ptr spdlog::basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool force_flush) +{ + return create(logger_name, filename, force_flush); +} + +inline std::shared_ptr spdlog::basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush) +{ + return create(logger_name, filename, force_flush); +} + // Create multi/single threaded rotating file logger inline std::shared_ptr spdlog::rotating_logger_mt(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files, bool force_flush) { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 62c81b56..dc2f4181 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -62,6 +62,13 @@ void set_async_mode(size_t queue_size, const async_overflow_policy overflow_poli // Turn off async mode void set_sync_mode(); + +// +// Create and register multi/single basic file logger +// +std::shared_ptr basic_logger_mt(const std::string& logger_name, const filename_t& filename,bool force_flush = false); +std::shared_ptr basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush = false); + // // Create and register multi/single threaded rotating file logger //