var names and some minor cleanups
This commit is contained in:
parent
8494590fb3
commit
a287bccd40
@ -1,12 +1,10 @@
|
||||
// example.cpp : Simple logger example
|
||||
//
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "c11log/logger.h"
|
||||
#include "c11log/sinks/async_sink.h"
|
||||
#include "c11log/sinks/file_sinks.h"
|
||||
#include "c11log/sinks/console_sinks.h"
|
||||
#include "c11log/details/log_msg.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
@ -16,16 +14,17 @@ using namespace std::chrono;
|
||||
using namespace c11log;
|
||||
using namespace utils;
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
if(argc || argv) {};
|
||||
const unsigned int howmany = 1000000;
|
||||
|
||||
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
|
||||
//auto fsink = std::make_shared<sinks::simple_file_sink>("simplelog", "txt");
|
||||
auto null_sink = std::make_shared<sinks::null_sink>();
|
||||
|
||||
|
||||
logger cout_logger ("cout", {null_sink, sinks::stdout_sink()});
|
||||
|
||||
cout_logger.info() << "Hello cout logger!";
|
||||
@ -33,7 +32,7 @@ int main(int argc, char* argv[])
|
||||
logger my_logger ("my_logger", {null_sink});
|
||||
|
||||
std::string s(100, '0');
|
||||
const unsigned int howmany = 5000000;
|
||||
|
||||
auto start = system_clock::now();
|
||||
for(unsigned int i = 0; i < howmany ; i++)
|
||||
my_logger.info() << s;
|
||||
|
@ -5,14 +5,11 @@
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
// Fast buffer
|
||||
// Fast memory storage
|
||||
// stores its contents on the stack when possible, in vector<char> otherwise
|
||||
// NOTE: User should be remember that returned buffer might be on the stack!!
|
||||
|
||||
namespace c11log
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
namespace c11log { namespace details {
|
||||
|
||||
template<std::size_t STACK_SIZE=128>
|
||||
class fast_buf
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// Faster than ostringstream--returns its string by ref
|
||||
|
||||
#include <ostream>
|
||||
#include "c11log/details/fast_buf.h"
|
||||
|
||||
namespace c11log
|
||||
@ -20,12 +20,6 @@ public:
|
||||
str_devicebuf& operator=(const str_devicebuf&) = delete;
|
||||
str_devicebuf& operator=(str_devicebuf&&) = delete;
|
||||
|
||||
/*
|
||||
const std::string& str_ref() const
|
||||
{
|
||||
return _str;
|
||||
}
|
||||
*/
|
||||
bufpair_t buf()
|
||||
{
|
||||
return _fastbuf.get();
|
||||
@ -33,7 +27,6 @@ public:
|
||||
|
||||
void reset_str()
|
||||
{
|
||||
//_str.clear();
|
||||
_fastbuf.clear();
|
||||
}
|
||||
|
||||
@ -47,20 +40,12 @@ protected:
|
||||
// reserve initially 128 bytes which should be enough for common log lines
|
||||
std::streamsize xsputn(const char_type* s, std::streamsize count) override
|
||||
{
|
||||
/*
|
||||
if(_str.capacity() < k_initial_reserve)
|
||||
{
|
||||
_str.reserve(k_initial_reserve);
|
||||
}
|
||||
_str.append(s, static_cast<unsigned int>(count));
|
||||
*/
|
||||
_fastbuf.append(s, static_cast<unsigned int>(count));
|
||||
return count;
|
||||
}
|
||||
|
||||
int_type overflow(int_type ch) override
|
||||
{
|
||||
|
||||
bool not_eofile = traits_type::not_eof(ch);
|
||||
if (not_eofile)
|
||||
{
|
||||
@ -70,7 +55,6 @@ protected:
|
||||
return not_eofile;
|
||||
}
|
||||
private:
|
||||
//std::string _str;
|
||||
fast_buf<192> _fastbuf;
|
||||
};
|
||||
|
||||
@ -83,12 +67,7 @@ public:
|
||||
fast_oss(const fast_oss& other) = delete;
|
||||
fast_oss(fast_oss&& other) = delete;
|
||||
fast_oss& operator=(const fast_oss& other) = delete;
|
||||
/*
|
||||
const std::string& str_ref() const
|
||||
{
|
||||
return _dev.str_ref();
|
||||
}
|
||||
*/
|
||||
|
||||
bufpair_t buf()
|
||||
{
|
||||
return _dev.buf();
|
||||
|
@ -38,12 +38,13 @@ public:
|
||||
line_logger& operator=(const line_logger&) = delete;
|
||||
line_logger& operator=(line_logger&&) = delete;
|
||||
|
||||
line_logger(line_logger&& other) :
|
||||
_callback_logger(other._callback_logger),
|
||||
// The move ctor should only be called on start of logging line,
|
||||
// where no logging happened yet for this line so no need to copy the string from the other
|
||||
line_logger(line_logger&& other) :
|
||||
_callback_logger(other._callback_logger),
|
||||
_oss(),
|
||||
_level(other._level) {};
|
||||
_level(other._level),
|
||||
_enabled(other._enabled) {}
|
||||
|
||||
|
||||
~line_logger()
|
||||
|
@ -67,7 +67,7 @@ private:
|
||||
std::string _logger_name = "";
|
||||
formatter_ptr _formatter;
|
||||
sinks_vector_t _sinks;
|
||||
std::atomic_int _atomic_level;
|
||||
std::atomic_int _logger_level;
|
||||
|
||||
void _log_it(const bufpair_t& buf, const level::level_enum level);
|
||||
|
||||
@ -91,7 +91,7 @@ inline c11log::logger::logger(const std::string& name, formatter_ptr f, sinks_in
|
||||
_sinks(sinks_list)
|
||||
{
|
||||
//Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here
|
||||
_atomic_level = level::INFO;
|
||||
_logger_level = level::INFO;
|
||||
}
|
||||
|
||||
inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_list) :
|
||||
@ -103,7 +103,7 @@ inline c11log::logger::logger(sinks_init_list sinks_list) :
|
||||
|
||||
inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enum msg_level)
|
||||
{
|
||||
return details::line_logger(this, msg_level, msg_level >= _atomic_level);
|
||||
return details::line_logger(this, msg_level, msg_level >= _logger_level);
|
||||
}
|
||||
|
||||
inline c11log::details::line_logger c11log::logger::debug()
|
||||
@ -136,17 +136,17 @@ inline const std::string& c11log::logger::get_name() const
|
||||
|
||||
inline void c11log::logger::set_level(c11log::level::level_enum level)
|
||||
{
|
||||
_atomic_level.store(level);
|
||||
_logger_level.store(level);
|
||||
}
|
||||
|
||||
inline c11log::level::level_enum c11log::logger::get_level() const
|
||||
{
|
||||
return static_cast<c11log::level::level_enum>(_atomic_level.load());
|
||||
return static_cast<c11log::level::level_enum>(_logger_level.load());
|
||||
}
|
||||
|
||||
inline bool c11log::logger::should_log(c11log::level::level_enum level) const
|
||||
{
|
||||
return level >= _atomic_level.load();
|
||||
return level >= _logger_level.load();
|
||||
}
|
||||
|
||||
inline void c11log::logger::_log_it(const bufpair_t& buf, const level::level_enum level)
|
||||
|
Loading…
Reference in New Issue
Block a user