diff --git a/c11logtest/c11logtest/ReadMe.txt b/c11logtest/c11logtest/ReadMe.txt
index 233ecc2a..40735cf8 100644
--- a/c11logtest/c11logtest/ReadMe.txt
+++ b/c11logtest/c11logtest/ReadMe.txt
@@ -1,27 +1,27 @@
========================================================================
- CONSOLE APPLICATION : c11logtest Project Overview
+ CONSOLE APPLICATION : spitlogtest Project Overview
========================================================================
-AppWizard has created this c11logtest application for you.
+AppWizard has created this spitlogtest application for you.
This file contains a summary of what you will find in each of the files that
-make up your c11logtest application.
+make up your spitlogtest application.
-c11logtest.vcxproj
+spitlogtest.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
-c11logtest.vcxproj.filters
+spitlogtest.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
-c11logtest.cpp
+spitlogtest.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
@@ -29,7 +29,7 @@ Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
- named c11logtest.pch and a precompiled types file named StdAfx.obj.
+ named spitlogtest.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
diff --git a/c11logtest/c11logtest/c11logtest.vcxproj b/c11logtest/c11logtest/c11logtest.vcxproj
index 0c290ae8..440ac229 100644
--- a/c11logtest/c11logtest/c11logtest.vcxproj
+++ b/c11logtest/c11logtest/c11logtest.vcxproj
@@ -13,7 +13,7 @@
{DC7F2F3E-0D0E-4324-A278-410DBC4045AD}
Win32Proj
- c11logtest
+ spitlogtest
@@ -52,7 +52,7 @@
Level3
Disabled
WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- ../../include
+ E:\devel\c11log\example;../../include
Console
@@ -69,7 +69,7 @@
true
true
WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- ../../include
+ E:\devel\c11log\example;../../include
false
StreamingSIMDExtensions2
@@ -85,28 +85,28 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/c11logtest/c11logtest/c11logtest.vcxproj.filters b/c11logtest/c11logtest/c11logtest.vcxproj.filters
index 9edef0a7..6087b328 100644
--- a/c11logtest/c11logtest/c11logtest.vcxproj.filters
+++ b/c11logtest/c11logtest/c11logtest.vcxproj.filters
@@ -33,71 +33,71 @@
Header Files
-
- Header Files\c11log
+
+ Header Files
-
- Header Files\c11log
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\sinks
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
-
- Header Files\c11log\details
+
+ Header Files
diff --git a/c11logtest/c11logtest/stdafx.cpp b/c11logtest/c11logtest/stdafx.cpp
index cb2b4191..0661e975 100644
--- a/c11logtest/c11logtest/stdafx.cpp
+++ b/c11logtest/c11logtest/stdafx.cpp
@@ -1,5 +1,5 @@
// stdafx.cpp : source file that includes just the standard includes
-// c11logtest.pch will be the pre-compiled header
+// spitlogtest.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
diff --git a/example/bench.cpp b/example/bench.cpp
index 18118424..717313e1 100644
--- a/example/bench.cpp
+++ b/example/bench.cpp
@@ -1,33 +1,33 @@
// example.cpp : Simple logger example
//
-#include "c11log/logger.h"
-#include "c11log/sinks/async_sink.h"
-#include "c11log/sinks/file_sinks.h"
-#include "c11log/sinks/stdout_sinks.h"
-#include "c11log/sinks/null_sink.h"
+#include "spitlog/logger.h"
+#include "spitlog/sinks/async_sink.h"
+#include "spitlog/sinks/file_sinks.h"
+#include "spitlog/sinks/stdout_sinks.h"
+#include "spitlog/sinks/null_sink.h"
#include "utils.h"
-#include "c11log/details/registry.h"
+#include "spitlog/details/registry.h"
using namespace std::chrono;
-using namespace c11log;
+using namespace spitlog;
using namespace utils;
int main(int argc, char* argv[])
{
try {
- const unsigned int howmany = argc <= 1 ? 500000 : atoi(argv[1]);
+ const unsigned int howmany = argc <= 1 ? 1500000 : atoi(argv[1]);
- //c11log::set_format("%t");
- auto console = c11log::create("reporter");
+ //spitlog::set_format("%t");
+ auto console = spitlog::create("reporter");
//console->set_format("[%n %l] %t");
- console->set_level(c11log::level::INFO);
+ console->set_level(spitlog::level::INFO);
console->info("Starting bench with", howmany, "iterations..");
- auto bench = c11log::create("bench", "myrotating", "txt", 1024 * 1024 * 1, 3, 0);
+ auto bench = spitlog::create("bench", "myrotating", "txt", 1024 * 1024 * 1, 10, 0);
- //auto bench = c11log::create("bench", "simplelog.txt", 1);
- //auto bench = c11log::create("bench");
+ //auto bench = spitlog::create("bench", "simplelog.txt", 1);
+ //auto bench = spitlog::create("bench");
auto start = system_clock::now();
for (unsigned int i = 0; i < howmany; ++i)
{
@@ -45,6 +45,7 @@ int main(int argc, char* argv[])
catch (std::exception &ex)
{
std::cerr << "Exception: " << ex.what() << std::endl;
+ perror("Last error");
}
return 0;
}
diff --git a/example/example.cpp b/example/example.cpp
index c9b0ae50..e216552e 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -3,11 +3,11 @@
#define FFLOG_ENABLE_TRACE
#include
-#include "c11log/logger.h"
-#include "c11log/sinks/stdout_sinks.h"
-#include "c11log/sinks/file_sinks.h"
+#include "spitlog/logger.h"
+#include "spitlog/sinks/stdout_sinks.h"
+#include "spitlog/sinks/file_sinks.h"
using namespace std;
-using namespace c11log;
+using namespace spitlog;
details::fast_oss f(const std::string& what)
diff --git a/include/c11log/details/logger_impl.h b/include/c11log/details/logger_impl.h
deleted file mode 100644
index 156b0872..00000000
--- a/include/c11log/details/logger_impl.h
+++ /dev/null
@@ -1,163 +0,0 @@
-#pragma once
-//
-// Logger implementation
-//
-
-
-#include "./line_logger.h"
-
-
-inline c11log::logger::logger(const std::string& logger_name, sinks_init_list sinks_list) :
- _name(logger_name),
- _sinks(sinks_list)
-{
- // no support under vs2013 for member initialization for std::atomic
- _level = level::INFO;
-}
-
-template
-inline c11log::logger::logger(const std::string& logger_name, const It& begin, const It& end) :
- _name(logger_name),
- _sinks(begin, end)
-{}
-
-
-inline void c11log::logger::set_formatter(c11log::formatter_ptr msg_formatter)
-{
- _formatter = msg_formatter;
-}
-
-inline void c11log::logger::set_format(const std::string& format)
-{
- _formatter = std::make_shared(format);
-}
-
-inline c11log::formatter_ptr c11log::logger::get_formatter() const
-{
- return _formatter;
-}
-
-
-template
-inline c11log::details::line_logger c11log::logger::log(level::level_enum lvl, const Args&... args) {
- bool msg_enabled = should_log(lvl);
- details::line_logger l(this, lvl, msg_enabled);
- if (msg_enabled)
- _variadic_log(l, args...);
- return l;
-}
-
-template
-inline c11log::details::line_logger c11log::logger::trace(const Args&... args)
-{
- return log(level::TRACE, args...);
-}
-
-template
-inline c11log::details::line_logger c11log::logger::debug(const Args&... args)
-{
- return log(level::DEBUG, args...);
-}
-
-template
-inline c11log::details::line_logger c11log::logger::info(const Args&... args)
-{
- return log(level::INFO, args...);
-}
-
-template
-inline c11log::details::line_logger c11log::logger::warn(const Args&... args)
-{
- return log(level::WARN, args...);
-}
-
-template
-inline c11log::details::line_logger c11log::logger::error(const Args&... args)
-{
- return log(level::ERR, args...);
-}
-
-template
-inline c11log::details::line_logger c11log::logger::critical(const Args&... args)
-{
- return log(level::CRITICAL, args...);
-}
-
-inline const std::string& c11log::logger::name() const
-{
- return _name;
-}
-
-inline void c11log::logger::set_level(c11log::level::level_enum log_level)
-{
- _level.store(log_level);
-}
-
-inline c11log::level::level_enum c11log::logger::level() const
-{
- return static_cast(_level.load());
-}
-
-inline bool c11log::logger::should_log(c11log::level::level_enum msg_level) const
-{
- return msg_level >= _level.load();
-}
-
-inline void c11log::logger::_variadic_log(c11log::details::line_logger&) {}
-
-template
-void c11log::logger::_variadic_log(c11log::details::line_logger& l, const First& first, const Rest&... rest)
-{
- l.write(first);
- l.write(' ');
- _variadic_log(l, rest...);
-}
-
-inline void c11log::logger::_log_msg(details::log_msg& msg)
-{
- //Use default formatter if not set
- if (!_formatter)
- _formatter = std::make_shared("%+");
- _formatter->format(msg);
- for (auto &sink : _sinks)
- sink->log(msg);
-}
-
-//
-// Global registry functions
-//
-#include "./registry.h"
-inline std::shared_ptr c11log::get(const std::string& name)
-{
- return details::registry::instance().get(name);
-}
-
-inline std::shared_ptr c11log::create(const std::string& logger_name, c11log::sinks_init_list sinks)
-{
- return details::registry::instance().create(logger_name, sinks);
-}
-
-
-template
-inline std::shared_ptr c11log::create(const std::string& logger_name, const Args&... args)
-{
- sink_ptr sink = std::make_shared(args...);
- return details::registry::instance().create(logger_name, { sink });
-}
-
-
-template
-inline std::shared_ptr c11log::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
-{
- return details::registry::instance().create(logger_name, std::forward(sinks_begin), std::forward(sinks_end));
-}
-
-inline void c11log::set_formatter(c11log::formatter_ptr f)
-{
- details::registry::instance().formatter(f);
-}
-
-inline void c11log::set_format(const std::string& format_string)
-{
- return details::registry::instance().set_format(format_string);
-}
diff --git a/include/c11log/common.h b/include/spitlog/common.h
similarity index 85%
rename from include/c11log/common.h
rename to include/spitlog/common.h
index 3bf48d0d..8e22060f 100644
--- a/include/c11log/common.h
+++ b/include/spitlog/common.h
@@ -3,7 +3,7 @@
#include
#include
-namespace c11log
+namespace spitlog
{
class formatter;
namespace sinks {
@@ -14,7 +14,7 @@ class sink;
using log_clock = std::chrono::system_clock;
using sink_ptr = std::shared_ptr < sinks::sink > ;
using sinks_init_list = std::initializer_list < sink_ptr > ;
-using formatter_ptr = std::shared_ptr;
+using formatter_ptr = std::shared_ptr;
//Log level enum
namespace level
@@ -31,7 +31,7 @@ typedef enum
} level_enum;
static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "fatal" };
-inline const char* to_str(c11log::level::level_enum l)
+inline const char* to_str(spitlog::level::level_enum l)
{
return level_names[l];
}
@@ -52,4 +52,4 @@ private:
};
-} //c11log
+} //spitlog
diff --git a/include/c11log/details/blocking_queue.h b/include/spitlog/details/blocking_queue.h
similarity index 99%
rename from include/c11log/details/blocking_queue.h
rename to include/spitlog/details/blocking_queue.h
index 8439088d..30e29046 100644
--- a/include/c11log/details/blocking_queue.h
+++ b/include/spitlog/details/blocking_queue.h
@@ -10,7 +10,7 @@
#include
#include
-namespace c11log
+namespace spitlog
{
namespace details
{
diff --git a/include/c11log/details/fast_istostr.h b/include/spitlog/details/fast_istostr.h
similarity index 98%
rename from include/c11log/details/fast_istostr.h
rename to include/spitlog/details/fast_istostr.h
index 7f375edc..6da3e3f2 100644
--- a/include/c11log/details/fast_istostr.h
+++ b/include/spitlog/details/fast_istostr.h
@@ -5,7 +5,7 @@
//Source: http://stackoverflow.com/a/4351484/192001
//Modified version to pad zeros according to padding arg
-namespace c11log {
+namespace spitlog {
namespace details {
const char digit_pairs[201] = {
diff --git a/include/c11log/details/fast_oss.h b/include/spitlog/details/fast_oss.h
similarity index 99%
rename from include/c11log/details/fast_oss.h
rename to include/spitlog/details/fast_oss.h
index 80cdd3be..611b648a 100644
--- a/include/c11log/details/fast_oss.h
+++ b/include/spitlog/details/fast_oss.h
@@ -9,7 +9,7 @@
#include "stack_buf.h"
#include
-namespace c11log
+namespace spitlog
{
namespace details
{
diff --git a/include/c11log/details/file_helper.h b/include/spitlog/details/file_helper.h
similarity index 80%
rename from include/c11log/details/file_helper.h
rename to include/spitlog/details/file_helper.h
index 0d5617f5..777dbc29 100644
--- a/include/c11log/details/file_helper.h
+++ b/include/spitlog/details/file_helper.h
@@ -16,7 +16,7 @@
-namespace c11log
+namespace spitlog
{
namespace details
{
@@ -70,7 +70,7 @@ public:
auto& buf = msg.formatted.buf();
size_t size = buf.size();
if(std::fwrite(buf.data(), sizeof(char), size, _fd) != size)
- throw fflog_exception("Failed writing to file " + _filename);
+ throw fflog_exception("Failed writing to file " + _filename);
if(--_flush_countdown == 0)
{
@@ -79,6 +79,25 @@ public:
}
}
+ const std::string& filename() const
+ {
+ return _filename;
+ }
+
+ static bool file_exists(const std::string& name)
+ {
+ FILE* file;
+ if (!os::fopen_s(&file, name.c_str(), "r"))
+ {
+ fclose(file);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
private:
FILE* _fd;
std::string _filename;
diff --git a/include/c11log/details/line_logger.h b/include/spitlog/details/line_logger.h
similarity index 97%
rename from include/c11log/details/line_logger.h
rename to include/spitlog/details/line_logger.h
index c3fd5bd2..a315e22a 100644
--- a/include/c11log/details/line_logger.h
+++ b/include/spitlog/details/line_logger.h
@@ -8,7 +8,7 @@
// Line logger class - aggregates operator<< calls to fast ostream
// and logs upon destruction
-namespace c11log
+namespace spitlog
{
namespace details
{
@@ -76,4 +76,4 @@ private:
bool _enabled;
};
} //Namespace details
-} // Namespace c11log
+} // Namespace spitlog
diff --git a/include/c11log/details/log_msg.h b/include/spitlog/details/log_msg.h
similarity index 98%
rename from include/c11log/details/log_msg.h
rename to include/spitlog/details/log_msg.h
index e52b8d9f..80d80621 100644
--- a/include/c11log/details/log_msg.h
+++ b/include/spitlog/details/log_msg.h
@@ -3,7 +3,7 @@
#include "../common.h"
#include "./fast_oss.h"
-namespace c11log
+namespace spitlog
{
namespace details
{
diff --git a/include/spitlog/details/logger_impl.h b/include/spitlog/details/logger_impl.h
new file mode 100644
index 00000000..a5ebf402
--- /dev/null
+++ b/include/spitlog/details/logger_impl.h
@@ -0,0 +1,163 @@
+#pragma once
+//
+// Logger implementation
+//
+
+
+#include "./line_logger.h"
+
+
+inline spitlog::logger::logger(const std::string& logger_name, sinks_init_list sinks_list) :
+ _name(logger_name),
+ _sinks(sinks_list)
+{
+ // no support under vs2013 for member initialization for std::atomic
+ _level = level::INFO;
+}
+
+template
+inline spitlog::logger::logger(const std::string& logger_name, const It& begin, const It& end) :
+ _name(logger_name),
+ _sinks(begin, end)
+{}
+
+
+inline void spitlog::logger::set_formatter(spitlog::formatter_ptr msg_formatter)
+{
+ _formatter = msg_formatter;
+}
+
+inline void spitlog::logger::set_format(const std::string& format)
+{
+ _formatter = std::make_shared(format);
+}
+
+inline spitlog::formatter_ptr spitlog::logger::get_formatter() const
+{
+ return _formatter;
+}
+
+
+template
+inline spitlog::details::line_logger spitlog::logger::log(level::level_enum lvl, const Args&... args) {
+ bool msg_enabled = should_log(lvl);
+ details::line_logger l(this, lvl, msg_enabled);
+ if (msg_enabled)
+ _variadic_log(l, args...);
+ return l;
+}
+
+template
+inline spitlog::details::line_logger spitlog::logger::trace(const Args&... args)
+{
+ return log(level::TRACE, args...);
+}
+
+template
+inline spitlog::details::line_logger spitlog::logger::debug(const Args&... args)
+{
+ return log(level::DEBUG, args...);
+}
+
+template
+inline spitlog::details::line_logger spitlog::logger::info(const Args&... args)
+{
+ return log(level::INFO, args...);
+}
+
+template
+inline spitlog::details::line_logger spitlog::logger::warn(const Args&... args)
+{
+ return log(level::WARN, args...);
+}
+
+template
+inline spitlog::details::line_logger spitlog::logger::error(const Args&... args)
+{
+ return log(level::ERR, args...);
+}
+
+template
+inline spitlog::details::line_logger spitlog::logger::critical(const Args&... args)
+{
+ return log(level::CRITICAL, args...);
+}
+
+inline const std::string& spitlog::logger::name() const
+{
+ return _name;
+}
+
+inline void spitlog::logger::set_level(spitlog::level::level_enum log_level)
+{
+ _level.store(log_level);
+}
+
+inline spitlog::level::level_enum spitlog::logger::level() const
+{
+ return static_cast(_level.load());
+}
+
+inline bool spitlog::logger::should_log(spitlog::level::level_enum msg_level) const
+{
+ return msg_level >= _level.load();
+}
+
+inline void spitlog::logger::_variadic_log(spitlog::details::line_logger&) {}
+
+template
+void spitlog::logger::_variadic_log(spitlog::details::line_logger& l, const First& first, const Rest&... rest)
+{
+ l.write(first);
+ l.write(' ');
+ _variadic_log(l, rest...);
+}
+
+inline void spitlog::logger::_log_msg(details::log_msg& msg)
+{
+ //Use default formatter if not set
+ if (!_formatter)
+ _formatter = std::make_shared("%+");
+ _formatter->format(msg);
+ for (auto &sink : _sinks)
+ sink->log(msg);
+}
+
+//
+// Global registry functions
+//
+#include "./registry.h"
+inline std::shared_ptr spitlog::get(const std::string& name)
+{
+ return details::registry::instance().get(name);
+}
+
+inline std::shared_ptr spitlog::create(const std::string& logger_name, spitlog::sinks_init_list sinks)
+{
+ return details::registry::instance().create(logger_name, sinks);
+}
+
+
+template
+inline std::shared_ptr spitlog::create(const std::string& logger_name, const Args&... args)
+{
+ sink_ptr sink = std::make_shared(args...);
+ return details::registry::instance().create(logger_name, { sink });
+}
+
+
+template
+inline std::shared_ptr spitlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
+{
+ return details::registry::instance().create(logger_name, std::forward(sinks_begin), std::forward(sinks_end));
+}
+
+inline void spitlog::set_formatter(spitlog::formatter_ptr f)
+{
+ details::registry::instance().formatter(f);
+}
+
+inline void spitlog::set_format(const std::string& format_string)
+{
+ return details::registry::instance().set_format(format_string);
+}
diff --git a/include/c11log/details/null_mutex.h b/include/spitlog/details/null_mutex.h
similarity index 89%
rename from include/c11log/details/null_mutex.h
rename to include/spitlog/details/null_mutex.h
index 5a87cd02..3ad3f000 100644
--- a/include/c11log/details/null_mutex.h
+++ b/include/spitlog/details/null_mutex.h
@@ -2,7 +2,7 @@
// null, no cost mutex
-namespace c11log {
+namespace spitlog {
namespace details {
struct null_mutex
{
diff --git a/include/c11log/details/os.h b/include/spitlog/details/os.h
similarity index 98%
rename from include/c11log/details/os.h
rename to include/spitlog/details/os.h
index a9067a07..19d2b36f 100644
--- a/include/c11log/details/os.h
+++ b/include/spitlog/details/os.h
@@ -7,7 +7,7 @@
#include
#endif
-namespace c11log
+namespace spitlog
{
namespace details
{
@@ -123,7 +123,7 @@ inline int utc_minutes_offset(const std::tm& tm = localtime())
} //os
} //details
-} //c11log
+} //spitlog
diff --git a/include/c11log/details/pattern_formatter_impl.h b/include/spitlog/details/pattern_formatter_impl.h
similarity index 97%
rename from include/c11log/details/pattern_formatter_impl.h
rename to include/spitlog/details/pattern_formatter_impl.h
index 7c74e485..0c3b2e5a 100644
--- a/include/c11log/details/pattern_formatter_impl.h
+++ b/include/spitlog/details/pattern_formatter_impl.h
@@ -10,7 +10,7 @@
#include "./fast_oss.h"
#include "./os.h"
-namespace c11log
+namespace spitlog
{
namespace details {
class flag_formatter
@@ -377,12 +377,12 @@ class full_formatter :public flag_formatter
///////////////////////////////////////////////////////////////////////////////
// pattern_formatter inline impl
///////////////////////////////////////////////////////////////////////////////
-inline c11log::pattern_formatter::pattern_formatter(const std::string& pattern)
+inline spitlog::pattern_formatter::pattern_formatter(const std::string& pattern)
{
compile_pattern(pattern);
}
-inline void c11log::pattern_formatter::compile_pattern(const std::string& pattern)
+inline void spitlog::pattern_formatter::compile_pattern(const std::string& pattern)
{
auto end = pattern.end();
std::unique_ptr user_chars;
@@ -411,7 +411,7 @@ inline void c11log::pattern_formatter::compile_pattern(const std::string& patter
}
}
-inline void c11log::pattern_formatter::handle_flag(char flag)
+inline void spitlog::pattern_formatter::handle_flag(char flag)
{
switch (flag)
{
@@ -523,7 +523,7 @@ inline void c11log::pattern_formatter::handle_flag(char flag)
}
-inline void c11log::pattern_formatter::format(details::log_msg& msg)
+inline void spitlog::pattern_formatter::format(details::log_msg& msg)
{
for (auto &f : _formatters)
{
diff --git a/include/c11log/details/registry.h b/include/spitlog/details/registry.h
similarity index 99%
rename from include/c11log/details/registry.h
rename to include/spitlog/details/registry.h
index 71c0738c..3773ba8f 100644
--- a/include/c11log/details/registry.h
+++ b/include/spitlog/details/registry.h
@@ -10,7 +10,7 @@
#include "../logger.h"
#include "../common.h"
-namespace c11log {
+namespace spitlog {
namespace details {
class registry {
public:
diff --git a/include/c11log/details/stack_buf.h b/include/spitlog/details/stack_buf.h
similarity index 97%
rename from include/c11log/details/stack_buf.h
rename to include/spitlog/details/stack_buf.h
index 6ea661ef..16b02d27 100644
--- a/include/c11log/details/stack_buf.h
+++ b/include/spitlog/details/stack_buf.h
@@ -7,7 +7,7 @@
// Fast memory storage on the stack when possible or in std::vector
-namespace c11log
+namespace spitlog
{
namespace details
{
@@ -108,4 +108,4 @@ private:
};
}
-} //namespace c11log { namespace details {
+} //namespace spitlog { namespace details {
diff --git a/include/c11log/formatter.h b/include/spitlog/formatter.h
similarity index 97%
rename from include/c11log/formatter.h
rename to include/spitlog/formatter.h
index 12c4dfca..9ca1427b 100644
--- a/include/c11log/formatter.h
+++ b/include/spitlog/formatter.h
@@ -1,7 +1,7 @@
#pragma once
#include "details/log_msg.h"
-namespace c11log
+namespace spitlog
{
namespace details {
class flag_formatter;
diff --git a/include/c11log/logger.h b/include/spitlog/logger.h
similarity index 86%
rename from include/c11log/logger.h
rename to include/spitlog/logger.h
index 9e4d0db7..88005638 100644
--- a/include/c11log/logger.h
+++ b/include/spitlog/logger.h
@@ -15,7 +15,7 @@
#include "sinks/base_sink.h"
#include "common.h"
-namespace c11log
+namespace spitlog
{
namespace details
@@ -70,14 +70,14 @@ private:
//
// Registry functions for easy loggers creation and retrieval
// example
-// auto console_logger = c11log::create("my_logger", c11log::sinks);
-// auto same_logger = c11log::get("my_logger");
+// auto console_logger = spitlog::create("my_logger", spitlog::sinks);
+// auto same_logger = spitlog::get("my_logger");
// auto file_logger = c11
//
std::shared_ptr get(const std::string& name);
std::shared_ptr create(const std::string& logger_name, sinks_init_list sinks);
template
-std::shared_ptr create(const std::string& logger_name, const Args&... args);
+std::shared_ptr create(const std::string& logger_name, const Args&... args);
template
std::shared_ptr create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end);
@@ -89,13 +89,13 @@ void set_format(const std::string& format_string);
// Trace & debug macros
//
#ifdef FFLOG_ENABLE_TRACE
-#define FFLOG_TRACE(logger, ...) logger->log(c11log::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
+#define FFLOG_TRACE(logger, ...) logger->log(spitlog::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
#else
#define FFLOG_TRACE(logger, ...) {}
#endif
#ifdef FFLOG_ENABLE_DEBUG
-#define FFLOG_DEBUG(logger, ...) logger->log(c11log::level::DEBUG, __VA_ARGS__)
+#define FFLOG_DEBUG(logger, ...) logger->log(spitlog::level::DEBUG, __VA_ARGS__)
#else
#define FFLOG_DEBUG(logger, ...) {}
#endif
diff --git a/include/c11log/sinks/async_sink.h b/include/spitlog/sinks/async_sink.h
similarity index 79%
rename from include/c11log/sinks/async_sink.h
rename to include/spitlog/sinks/async_sink.h
index 3415c630..7f76b824 100644
--- a/include/c11log/sinks/async_sink.h
+++ b/include/spitlog/sinks/async_sink.h
@@ -13,7 +13,7 @@
#include
-namespace c11log
+namespace spitlog
{
namespace sinks
{
@@ -53,26 +53,26 @@ private:
///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation
///////////////////////////////////////////////////////////////////////////////
-inline c11log::sinks::async_sink::async_sink(const q_type::size_type max_queue_size)
+inline spitlog::sinks::async_sink::async_sink(const q_type::size_type max_queue_size)
:_sinks(),
_active(true),
_q(max_queue_size),
_back_thread(&async_sink::_thread_loop, this)
{}
-inline c11log::sinks::async_sink::~async_sink()
+inline spitlog::sinks::async_sink::~async_sink()
{
_shutdown();
}
-inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
+inline void spitlog::sinks::async_sink::_sink_it(const details::log_msg& msg)
{
if(!_active)
return;
_q.push(msg);
}
-inline void c11log::sinks::async_sink::_thread_loop()
+inline void spitlog::sinks::async_sink::_thread_loop()
{
static std::chrono::seconds pop_timeout { 1 };
while (_active)
@@ -90,27 +90,27 @@ inline void c11log::sinks::async_sink::_thread_loop()
}
}
-inline void c11log::sinks::async_sink::add_sink(c11log::sink_ptr s)
+inline void spitlog::sinks::async_sink::add_sink(spitlog::sink_ptr s)
{
std::lock_guard guard(_mutex);
_sinks.push_back(s);
}
-inline void c11log::sinks::async_sink::remove_sink(c11log::sink_ptr s)
+inline void spitlog::sinks::async_sink::remove_sink(spitlog::sink_ptr s)
{
std::lock_guard guard(_mutex);
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), s), _sinks.end());
}
-inline c11log::sinks::async_sink::q_type& c11log::sinks::async_sink::q()
+inline spitlog::sinks::async_sink::q_type& spitlog::sinks::async_sink::q()
{
return _q;
}
-inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
+inline void spitlog::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
{
if(timeout > std::chrono::milliseconds::zero())
{
@@ -124,7 +124,7 @@ inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds&
}
-inline void c11log::sinks::async_sink::_shutdown()
+inline void spitlog::sinks::async_sink::_shutdown()
{
std::lock_guard guard(_mutex);
if(_active)
diff --git a/include/c11log/sinks/base_sink.h b/include/spitlog/sinks/base_sink.h
similarity index 97%
rename from include/c11log/sinks/base_sink.h
rename to include/spitlog/sinks/base_sink.h
index 6b8244c1..254a680b 100644
--- a/include/c11log/sinks/base_sink.h
+++ b/include/spitlog/sinks/base_sink.h
@@ -14,7 +14,7 @@
#include "../details/log_msg.h"
-namespace c11log
+namespace spitlog
{
namespace sinks
{
diff --git a/include/c11log/sinks/file_sinks.h b/include/spitlog/sinks/file_sinks.h
similarity index 77%
rename from include/c11log/sinks/file_sinks.h
rename to include/spitlog/sinks/file_sinks.h
index 15f3e7d6..2a555829 100644
--- a/include/c11log/sinks/file_sinks.h
+++ b/include/spitlog/sinks/file_sinks.h
@@ -1,15 +1,16 @@
#pragma once
-#include
+
#include
#include "./base_sink.h"
#include "../details/null_mutex.h"
#include "../details/file_helper.h"
+#include "../details/fast_oss.h"
-namespace c11log
+namespace spitlog
{
namespace sinks
{
@@ -56,7 +57,7 @@ public:
_current_size(0),
_file_helper(flush_inverval)
{
- _file_helper.open(_calc_filename(_base_filename, 0, _extension));
+ _file_helper.open(calc_filename(_base_filename, 0, _extension));
}
protected:
@@ -73,9 +74,9 @@ protected:
private:
- static std::string _calc_filename(const std::string& filename, std::size_t index, const std::string& extension)
+ static std::string calc_filename(const std::string& filename, std::size_t index, const std::string& extension)
{
- std::ostringstream oss;
+ details::fast_oss oss;
if (index)
oss << filename << "." << index << "." << extension;
else
@@ -96,11 +97,19 @@ private:
_file_helper.close();
for (auto i = _max_files; i > 0; --i)
{
- std::string src = _calc_filename(_base_filename, i - 1, _extension);
- std::string target = _calc_filename(_base_filename, i, _extension);
- std::rename(src.c_str(), target.c_str());
+ std::string src = calc_filename(_base_filename, i - 1, _extension);
+ std::string target = calc_filename(_base_filename, i, _extension);
+
+ if (details::file_helper::file_exists(target))
+ std::remove(target.c_str());
+ if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str()))
+ {
+ throw fflog_exception("rotating_file_sink: failed renaming " + src + " to " + target);
+ }
}
- _file_helper.open(_calc_filename(_base_filename, 0, _extension));
+ auto cur_name = _file_helper.filename();
+ std::remove(cur_name.c_str());
+ _file_helper.open(cur_name);
}
std::string _base_filename;
std::string _extension;
@@ -128,7 +137,7 @@ public:
_midnight_tp (_calc_midnight_tp() ),
_file_helper(flush_inverval)
{
- _file_helper.open(_calc_filename(_base_filename, _extension));
+ _file_helper.open(calc_filename(_base_filename, _extension));
}
protected:
@@ -137,7 +146,7 @@ protected:
if (std::chrono::system_clock::now() >= _midnight_tp)
{
_file_helper.close();
- _file_helper.open(_calc_filename(_base_filename, _extension));
+ _file_helper.open(calc_filename(_base_filename, _extension));
_midnight_tp = _calc_midnight_tp();
}
_file_helper.write(msg);
@@ -150,17 +159,17 @@ private:
using namespace std::chrono;
auto now = system_clock::now();
time_t tnow = std::chrono::system_clock::to_time_t(now);
- tm date = c11log::details::os::localtime(tnow);
+ tm date = spitlog::details::os::localtime(tnow);
date.tm_hour = date.tm_min = date.tm_sec = 0;
auto midnight = std::chrono::system_clock::from_time_t(std::mktime(&date));
return system_clock::time_point(midnight + hours(24));
}
//Create filename for the form basename.YYYY-MM-DD.extension
- static std::string _calc_filename(const std::string& basename, const std::string& extension)
+ static std::string calc_filename(const std::string& basename, const std::string& extension)
{
- std::tm tm = c11log::details::os::localtime();
- std::ostringstream oss;
+ std::tm tm = spitlog::details::os::localtime();
+ fast_oss oss;
oss << basename << '.';
oss << tm.tm_year + 1900 << '-' << std::setw(2) << std::setfill('0') << tm.tm_mon + 1 << '-' << tm.tm_mday;
oss << '.' << extension;
diff --git a/include/c11log/sinks/null_sink.h b/include/spitlog/sinks/null_sink.h
similarity index 94%
rename from include/c11log/sinks/null_sink.h
rename to include/spitlog/sinks/null_sink.h
index b8b798cd..b79ccf32 100644
--- a/include/c11log/sinks/null_sink.h
+++ b/include/spitlog/sinks/null_sink.h
@@ -4,7 +4,7 @@
#include "../details/null_mutex.h"
-namespace c11log {
+namespace spitlog {
namespace sinks {
template
diff --git a/include/c11log/sinks/ostream_sink.h b/include/spitlog/sinks/ostream_sink.h
similarity index 97%
rename from include/c11log/sinks/ostream_sink.h
rename to include/spitlog/sinks/ostream_sink.h
index 2332a8a1..6b8ef6c3 100644
--- a/include/c11log/sinks/ostream_sink.h
+++ b/include/spitlog/sinks/ostream_sink.h
@@ -7,7 +7,7 @@
#include "../details/null_mutex.h"
#include "./base_sink.h"
-namespace c11log
+namespace spitlog
{
namespace sinks
{
diff --git a/include/c11log/sinks/sink.h b/include/spitlog/sinks/sink.h
similarity index 90%
rename from include/c11log/sinks/sink.h
rename to include/spitlog/sinks/sink.h
index 4338019e..1aac1797 100644
--- a/include/c11log/sinks/sink.h
+++ b/include/spitlog/sinks/sink.h
@@ -2,7 +2,7 @@
#include "../details/log_msg.h"
-namespace c11log
+namespace spitlog
{
namespace sinks
{
diff --git a/include/c11log/sinks/stdout_sinks.h b/include/spitlog/sinks/stdout_sinks.h
similarity index 97%
rename from include/c11log/sinks/stdout_sinks.h
rename to include/spitlog/sinks/stdout_sinks.h
index 0dfa6934..d79bec5b 100644
--- a/include/c11log/sinks/stdout_sinks.h
+++ b/include/spitlog/sinks/stdout_sinks.h
@@ -5,7 +5,7 @@
#include "./ostream_sink.h"
#include "../details/null_mutex.h"
-namespace c11log
+namespace spitlog
{
namespace sinks
{