diff --git a/c11logtest/c11logtest/c11logtest.vcxproj b/c11logtest/c11logtest/c11logtest.vcxproj
index a28d09cf..c827e71e 100644
--- a/c11logtest/c11logtest/c11logtest.vcxproj
+++ b/c11logtest/c11logtest/c11logtest.vcxproj
@@ -84,7 +84,7 @@
-
+
diff --git a/c11logtest/c11logtest/c11logtest.vcxproj.filters b/c11logtest/c11logtest/c11logtest.vcxproj.filters
index 9ee71f3d..4b803831 100644
--- a/c11logtest/c11logtest/c11logtest.vcxproj.filters
+++ b/c11logtest/c11logtest/c11logtest.vcxproj.filters
@@ -33,9 +33,6 @@
Header Files
-
- Header Files\c11log
-
Header Files\c11log
@@ -90,6 +87,9 @@
Header Files\c11log\sinks
+
+ Header Files\c11log
+
diff --git a/example/example.cpp b/example/example.cpp
index 6401c5d7..b17e4873 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -20,14 +20,14 @@ int main(int argc, char* argv[])
const unsigned int howmany = argc <= 1 ? 10000 : atoi(argv[1]);
- logger cout_logger("example", std::make_shared());
+ logger cout_logger("example", std::make_shared());
cout_logger.info() << "Hello logger";
//auto nullsink = std::make_shared>();
- //auto nullsink = std::make_shared>();
- auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, 1);
- //auto as = std::make_shared(1000);
- //as->add_sink(fsink);
+ auto nullsink = std::make_shared>();
+ auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, 10);
+ auto as = std::make_shared(1000);
+
logger my_logger("my_logger", fsink);
@@ -36,7 +36,7 @@ int main(int argc, char* argv[])
for (unsigned int i = 1; i <= howmany; ++i)
my_logger.info() << "Hello logger: msg #" << i;
- //as->shutdown(std::chrono::milliseconds(15000));
+
auto delta = system_clock::now() - start;
auto delta_d = duration_cast> (delta).count();
diff --git a/include/c11log/common_types.h b/include/c11log/common_types.h
deleted file mode 100644
index 527996bd..00000000
--- a/include/c11log/common_types.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#include
-
-namespace c11log
-{
-
-typedef std::chrono::system_clock log_clock;
-
-namespace level
-{
-typedef enum
-{
- TRACE,
- DEBUG,
- INFO,
- WARNING,
- ERROR,
- CRITICAL,
- FATAL,
- NONE = 99
-} level_enum;
-
-static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "fatal" };
-inline const char* to_str(c11log::level::level_enum l)
-{
- return level_names[l];
-}
-} //level
-} //c11log
diff --git a/include/c11log/details/line_logger.h b/include/c11log/details/line_logger.h
index f0a53885..9c866b55 100644
--- a/include/c11log/details/line_logger.h
+++ b/include/c11log/details/line_logger.h
@@ -1,7 +1,7 @@
#pragma once
#include
-#include "../common_types.h"
+#include "../common.h"
#include "../logger.h"
#include "fast_oss.h"
diff --git a/include/c11log/details/log_msg.h b/include/c11log/details/log_msg.h
index bed7f414..b8920a0f 100644
--- a/include/c11log/details/log_msg.h
+++ b/include/c11log/details/log_msg.h
@@ -1,6 +1,7 @@
#pragma once
-#include "../common_types.h"
+#include
+#include "../common.h"
namespace c11log
{
@@ -16,7 +17,6 @@ struct log_msg
raw(),
formatted() {}
-
log_msg(const log_msg& other):
logger_name(other.logger_name),
level(other.level),
diff --git a/include/c11log/formatter.h b/include/c11log/formatter.h
index 955d7237..ae77201a 100644
--- a/include/c11log/formatter.h
+++ b/include/c11log/formatter.h
@@ -8,7 +8,7 @@
#include
#include
-#include "common_types.h"
+#include "common.h"
#include "details/os.h"
#include "details/log_msg.h"
#include "details/fast_oss.h"
diff --git a/include/c11log/logger.h b/include/c11log/logger.h
index ac0179a9..1b70866c 100644
--- a/include/c11log/logger.h
+++ b/include/c11log/logger.h
@@ -8,8 +8,7 @@
#include
#include "sinks/base_sink.h"
-#include "common_types.h"
-
+#include "common.h"
diff --git a/include/c11log/sinks/async_sink.h b/include/c11log/sinks/async_sink.h
index cedb31ee..9648fc0d 100644
--- a/include/c11log/sinks/async_sink.h
+++ b/include/c11log/sinks/async_sink.h
@@ -8,6 +8,7 @@
#include "base_sink.h"
#include "../logger.h"
#include "../details/blocking_queue.h"
+#include "../details/null_mutex.h"
#include "../details/log_msg.h"
#include
@@ -17,8 +18,7 @@ namespace c11log
namespace sinks
{
-template
-class async_sink : public base_sink
+class async_sink : public base_sink
{
public:
using q_type = details::blocking_queue;
@@ -26,7 +26,6 @@ public:
explicit async_sink(const q_type::size_type max_queue_size);
//Stop logging and join the back thread
- // TODO: limit with timeout of the join and kill it afterwards?
~async_sink();
void add_sink(logger::sink_ptr sink);
void remove_sink(logger::sink_ptr sink_ptr);
@@ -46,7 +45,7 @@ private:
std::thread _back_thread;
//Clear all remaining messages(if any), stop the _back_thread and join it
void _shutdown();
- std::mutex _shutdown_mutex;
+ std::mutex _mutex;
};
}
}
@@ -54,30 +53,26 @@ private:
///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation
///////////////////////////////////////////////////////////////////////////////
-template
-inline c11log::sinks::async_sink::async_sink(const q_type::size_type max_queue_size)
+inline c11log::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)
{}
-template
-inline c11log::sinks::async_sink::~async_sink()
+inline c11log::sinks::async_sink::~async_sink()
{
_shutdown();
}
-template
-inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
+inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
{
if(!_active || msg.formatted.empty())
return;
_q.push(msg);
}
-template
-inline void c11log::sinks::async_sink::_thread_loop()
+inline void c11log::sinks::async_sink::_thread_loop()
{
static std::chrono::seconds pop_timeout { 1 };
while (_active)
@@ -95,27 +90,27 @@ inline void c11log::sinks::async_sink::_thread_loop()
}
}
-template
-inline void c11log::sinks::async_sink::add_sink(logger::sink_ptr sink)
+inline void c11log::sinks::async_sink::add_sink(logger::sink_ptr sink)
{
+ std::lock_guard guard(_mutex);
_sinks.push_back(sink);
}
-template
-inline void c11log::sinks::async_sink::remove_sink(logger::sink_ptr sink)
+
+inline void c11log::sinks::async_sink::remove_sink(logger::sink_ptr sink)
{
+ std::lock_guard guard(_mutex);
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink), _sinks.end());
}
-/*
-template
-inline c11log::sinks::async_sink::q_type& c11log::sinks::async_sink::q()
+
+
+inline c11log::sinks::async_sink::q_type& c11log::sinks::async_sink::q()
{
return _q;
-}*/
+}
-template
-inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
+inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
{
if(timeout > std::chrono::milliseconds::zero())
{
@@ -129,10 +124,9 @@ inline void c11log::sinks::async_sink::shutdown(const std::chrono::millis
}
-template
-inline void c11log::sinks::async_sink::_shutdown()
+inline void c11log::sinks::async_sink::_shutdown()
{
- std::lock_guard guard(_shutdown_mutex);
+ std::lock_guard guard(_mutex);
if(_active)
{
_active = false;
diff --git a/include/c11log/sinks/base_sink.h b/include/c11log/sinks/base_sink.h
index f880bc23..4b583ddb 100644
--- a/include/c11log/sinks/base_sink.h
+++ b/include/c11log/sinks/base_sink.h
@@ -5,7 +5,7 @@
#include
#include "isink.h"
#include "../formatter.h"
-#include "../common_types.h"
+#include "../common.h"
#include "../details/log_msg.h"
@@ -23,7 +23,7 @@ public:
base_sink(const base_sink&) = delete;
base_sink& operator=(const base_sink&) = delete;
- void log(const details::log_msg& msg)
+ void log(const details::log_msg& msg) override
{
if (_enabled)
{
@@ -32,12 +32,12 @@ public:
}
};
- void enable(bool enabled)
+ void enable(bool enabled) override
{
_enabled = enabled;
}
- bool is_enabled()
+ bool is_enabled() override
{
return _enabled.load();
}
@@ -48,8 +48,5 @@ protected:
std::atomic _enabled;
};
-
-
-
}
}
diff --git a/include/c11log/sinks/file_sinks.h b/include/c11log/sinks/file_sinks.h
index bcbb55bc..9eade65c 100644
--- a/include/c11log/sinks/file_sinks.h
+++ b/include/c11log/sinks/file_sinks.h
@@ -87,12 +87,10 @@ private:
}
- // Rotate old files:
+ // Rotate files:
// log.txt -> log.1.txt
- // log.n-1.txt -> log.n.txt
- // log.n-2.txt -> log.n-1.txt
- // log.n-3.txt ->..
- // log.n.txt -> log.txt
+ // ..
+ // log.n.txt -> log.n+1.txt
void _rotate()
diff --git a/include/c11log/sinks/ostream_sink.h b/include/c11log/sinks/ostream_sink.h
index 9f603d69..507e343b 100644
--- a/include/c11log/sinks/ostream_sink.h
+++ b/include/c11log/sinks/ostream_sink.h
@@ -26,7 +26,6 @@ protected:
{
_ostream << msg.formatted;
}
-
std::ostream& _ostream;
};