From fbddb5a5ca0a8510f87b9e916257749e9c7576cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjell=20Hedsr=C3=B6m?= Date: Wed, 17 Feb 2016 00:25:55 -0700 Subject: [PATCH] added new API for AddDefaultLogger to API --- API.markdown | 18 ++++++++++++++++++ test_unit/test_filechange.cpp | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/API.markdown b/API.markdown index 3342e96..931c0f0 100644 --- a/API.markdown +++ b/API.markdown @@ -89,6 +89,24 @@ A logging sink is not required to be a subclass of a specific type. The only req ### Using the default sink Sink creation is defined in [logworker.hpp](src/g3log/logworker.hpp) and used in [logworker.cpp](src/logworker.cpp). For in-depth knowlege regarding sink implementation details you can look at [sinkhandle.hpp](src/g3log/sinkhandle.hpp) and [sinkwrapper.hpp](src/g3log/sinkwrapper.hpp) +``` + std::unique_ptr addDefaultLogger( + const std::string& log_prefix + , const std::string& log_directory + , const std::string& default_id = "g3log"); +``` + +With the default id left as is (i.e. "g3log") a creation of the logger in the unit test "test_filechange" would look like this +``` + const std::string directory = "./"; + const std::string name = "(ReplaceLogFile)"; + auto worker = g3::LogWorker::createLogWorker(); + auto handle = worker->addDefaultLogger(name, directory); +``` +The resulting filename would be something like: +``` +./(ReplaceLogFile).g3log.20160217-001406.log +``` ## LOG flushing diff --git a/test_unit/test_filechange.cpp b/test_unit/test_filechange.cpp index ec619af..2a27e4d 100644 --- a/test_unit/test_filechange.cpp +++ b/test_unit/test_filechange.cpp @@ -154,11 +154,12 @@ int main(int argc, char* argv[]) { testing_helpers::ScopedOut scopedCerr(std::cerr, &cerrDump); auto worker = g3::LogWorker::createLogWorker(); - auto handle = worker->addDefaultLogger(kReplaceFileName, name_path_1, "kjell"); + auto handle = worker->addDefaultLogger(kReplaceFileName, name_path_1); g_logger_ptr = worker.get(); g_filesink_handler = handle.get(); last_log_file = g_filesink_handler->call(&g3::FileSink::fileName).get(); - //cleaner.addLogToClean(last_log_file); + std::cout << "log file at: " << last_log_file << std::endl; + cleaner.addLogToClean(last_log_file); g3::initializeLogging(g_logger_ptr); @@ -173,6 +174,6 @@ int main(int argc, char* argv[]) { } std::cout << "FINISHED WITH THE TESTING" << std::endl; // cleaning up - //cleaner.addLogToClean(last_log_file); + cleaner.addLogToClean(last_log_file); return return_value; } \ No newline at end of file