mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
line_logger fixes
This commit is contained in:
parent
afb4f1d8fa
commit
4c367a4bb5
@ -23,19 +23,19 @@ int main(int argc, char* argv[])
|
|||||||
logger cout_logger ("", sinks::stdout_sink());
|
logger cout_logger ("", sinks::stdout_sink());
|
||||||
cout_logger.info() << "Hello " << "man";
|
cout_logger.info() << "Hello " << "man";
|
||||||
|
|
||||||
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
|
auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
|
||||||
auto fsink2 = std::make_shared<sinks::rotating_file_sink>("lllog", "txt", 1024*1024*50 , 5, 0);
|
auto nullsink = sinks::null_sink::get();
|
||||||
|
//auto as = std::make_shared<sinks::async_sink>(1000);
|
||||||
|
//as->add_sink(sinks::null_sink::get());
|
||||||
|
|
||||||
auto as = std::make_shared<sinks::async_sink>(1000);
|
logger my_logger ("my_logger", nullsink);
|
||||||
as->add_sink(sinks::null_sink::get());
|
|
||||||
|
|
||||||
logger my_logger ("my_logger", as);
|
|
||||||
|
|
||||||
auto start = system_clock::now();
|
auto start = system_clock::now();
|
||||||
for(unsigned int i = 1; i <= howmany ; ++i)
|
for(unsigned int i = 1; i <= howmany ; ++i)
|
||||||
my_logger.info() << "Hello logger: " << i;
|
my_logger.debug() << "Hello logger: ";
|
||||||
|
|
||||||
auto s = howmany - as->q().size();
|
//auto s = howmany - as->q().size();
|
||||||
|
auto s = howmany;
|
||||||
auto delta = system_clock::now() - start;
|
auto delta = system_clock::now() - start;
|
||||||
auto delta_d = duration_cast<duration<double>> (delta).count();
|
auto delta_d = duration_cast<duration<double>> (delta).count();
|
||||||
|
|
||||||
|
@ -4,9 +4,8 @@
|
|||||||
#include "../logger.h"
|
#include "../logger.h"
|
||||||
#include "stack_oss.h"
|
#include "stack_oss.h"
|
||||||
|
|
||||||
|
// line_logger class.
|
||||||
// line logger class. should be used by the logger as an rvalue only.
|
// aggregates single log line (on the stack if possibe) and calls the logger upon destruction
|
||||||
// aggregates logging string until the end of the line and then calls the logger upon destruction
|
|
||||||
|
|
||||||
namespace c11log
|
namespace c11log
|
||||||
{
|
{
|
||||||
@ -21,7 +20,8 @@ public:
|
|||||||
_callback_logger(callback_logger),
|
_callback_logger(callback_logger),
|
||||||
_log_msg(msg_level),
|
_log_msg(msg_level),
|
||||||
_oss(),
|
_oss(),
|
||||||
_enabled(enabled)
|
_enabled(enabled),
|
||||||
|
_empty(true)
|
||||||
{
|
{
|
||||||
if(enabled)
|
if(enabled)
|
||||||
{
|
{
|
||||||
@ -48,8 +48,8 @@ public:
|
|||||||
_enabled(other._enabled) {}
|
_enabled(other._enabled) {}
|
||||||
|
|
||||||
~line_logger()
|
~line_logger()
|
||||||
{
|
{
|
||||||
if (_enabled)
|
if (!_empty)
|
||||||
{
|
{
|
||||||
_oss << os::eol();
|
_oss << os::eol();
|
||||||
_log_msg.msg_buf = _oss.buf();
|
_log_msg.msg_buf = _oss.buf();
|
||||||
@ -61,7 +61,10 @@ public:
|
|||||||
line_logger& operator<<(const T& what)
|
line_logger& operator<<(const T& what)
|
||||||
{
|
{
|
||||||
if (_enabled)
|
if (_enabled)
|
||||||
|
{
|
||||||
_oss << what;
|
_oss << what;
|
||||||
|
_empty = false;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +73,7 @@ private:
|
|||||||
log_msg _log_msg;
|
log_msg _log_msg;
|
||||||
details::stack_oss _oss;
|
details::stack_oss _oss;
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
|
bool _empty;
|
||||||
};
|
};
|
||||||
} //Namespace details
|
} //Namespace details
|
||||||
} // Namespace c11log
|
} // Namespace c11log
|
||||||
|
@ -85,7 +85,7 @@ public:
|
|||||||
_v.clear();
|
_v.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bufpair_t get()
|
bufpair_t get() const
|
||||||
{
|
{
|
||||||
if(!_v.empty())
|
if(!_v.empty())
|
||||||
return bufpair_t(_v.data(), _v.size());
|
return bufpair_t(_v.data(), _v.size());
|
||||||
@ -93,7 +93,7 @@ public:
|
|||||||
return bufpair_t(_stack_buf.data(), _stack_size);
|
return bufpair_t(_stack_buf.data(), _stack_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size()
|
std::size_t size() const
|
||||||
{
|
{
|
||||||
if(!_v.empty())
|
if(!_v.empty())
|
||||||
return _v.size();
|
return _v.size();
|
||||||
|
@ -21,12 +21,12 @@ public:
|
|||||||
stack_devicebuf& operator=(const stack_devicebuf&) = delete;
|
stack_devicebuf& operator=(const stack_devicebuf&) = delete;
|
||||||
stack_devicebuf& operator=(stack_devicebuf&&) = delete;
|
stack_devicebuf& operator=(stack_devicebuf&&) = delete;
|
||||||
|
|
||||||
bufpair_t buf()
|
bufpair_t buf() const
|
||||||
{
|
{
|
||||||
return _stackbuf.get();
|
return _stackbuf.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size()
|
std::size_t size() const
|
||||||
{
|
{
|
||||||
return _stackbuf.size();
|
return _stackbuf.size();
|
||||||
}
|
}
|
||||||
@ -67,12 +67,12 @@ public:
|
|||||||
stack_oss(stack_oss&& other) = delete;
|
stack_oss(stack_oss&& other) = delete;
|
||||||
stack_oss& operator=(const stack_oss& other) = delete;
|
stack_oss& operator=(const stack_oss& other) = delete;
|
||||||
|
|
||||||
bufpair_t buf()
|
bufpair_t buf() const
|
||||||
{
|
{
|
||||||
return _dev.buf();
|
return _dev.buf();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size()
|
std::size_t size() const
|
||||||
{
|
{
|
||||||
return _dev.size();
|
return _dev.size();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user