mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
returned fast_oss with optimizations
This commit is contained in:
@@ -10,11 +10,14 @@
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace c11log {
|
||||
namespace details {
|
||||
namespace c11log
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class blocking_queue {
|
||||
class blocking_queue
|
||||
{
|
||||
public:
|
||||
using queue_t = std::queue<T>;
|
||||
using size_type = typename queue_t::size_type;
|
||||
|
@@ -5,10 +5,13 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace c11log {
|
||||
namespace c11log
|
||||
{
|
||||
class logger;
|
||||
namespace details {
|
||||
class factory {
|
||||
namespace details
|
||||
{
|
||||
class factory
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr<c11log::logger> logger_ptr;
|
||||
typedef std::unordered_map<std::string, logger_ptr> logger_map;
|
||||
|
@@ -1,27 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
// Fast ostringstream like supprt which return its string by ref and nothing more
|
||||
|
||||
#include<streambuf>
|
||||
#include<string>
|
||||
namespace c11log {
|
||||
namespace details {
|
||||
|
||||
class str_devicebuf:public std::streambuf {
|
||||
namespace c11log
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
|
||||
class str_devicebuf:public std::streambuf
|
||||
{
|
||||
public:
|
||||
str_devicebuf() = default;
|
||||
~str_devicebuf() = default;
|
||||
str_devicebuf(const str_devicebuf& other):std::streambuf(),_str(other._str) {}
|
||||
|
||||
str_devicebuf(str_devicebuf&& other) :std::streambuf(), _str(std::move(other._str)) {
|
||||
other._str.clear();
|
||||
}
|
||||
|
||||
str_devicebuf(const str_devicebuf& other) = delete;
|
||||
str_devicebuf(str_devicebuf&& other) = delete;
|
||||
str_devicebuf& operator=(const str_devicebuf&) = delete;
|
||||
str_devicebuf& operator=(str_devicebuf&&) = delete;
|
||||
|
||||
|
||||
const std::string& str_ref() const {
|
||||
return _str;
|
||||
std::ostringstream oss;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
@@ -47,29 +49,22 @@ private:
|
||||
std::string _str;
|
||||
};
|
||||
|
||||
class fast_oss:public std::ostream {
|
||||
class fast_oss:public std::ostream
|
||||
{
|
||||
public:
|
||||
fast_oss():std::ostream(&_dev) {}
|
||||
~fast_oss() = default;
|
||||
|
||||
fast_oss(const fast_oss& other) :std::basic_ios<char>(), std::ostream(&_dev), _dev(other._dev) {}
|
||||
|
||||
fast_oss(fast_oss&& other) :std::basic_ios<char>(), std::ostream(&_dev), _dev(std::move(other._dev)) {}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
const std::string str() const {
|
||||
return _dev.str_ref();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_dev.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
str_devicebuf _dev;
|
||||
};
|
||||
|
@@ -3,9 +3,12 @@
|
||||
#include <iostream>
|
||||
// Flush to file every X writes..
|
||||
|
||||
namespace c11log {
|
||||
namespace details {
|
||||
class file_flush_helper {
|
||||
namespace c11log
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
class file_flush_helper
|
||||
{
|
||||
public:
|
||||
explicit file_flush_helper(const std::chrono::milliseconds &flush_every): _flush_every(flush_every), _last_flush() {};
|
||||
|
||||
|
@@ -2,13 +2,17 @@
|
||||
|
||||
#include "../common_types.h"
|
||||
#include "../logger.h"
|
||||
#include "fast_oss.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace c11log {
|
||||
namespace c11log
|
||||
{
|
||||
class logger;
|
||||
namespace details {
|
||||
namespace details
|
||||
{
|
||||
|
||||
class line_logger {
|
||||
class line_logger
|
||||
{
|
||||
public:
|
||||
line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled):
|
||||
_callback_logger(callback_logger),
|
||||
@@ -25,7 +29,7 @@ public:
|
||||
|
||||
line_logger(line_logger&& other) :
|
||||
_callback_logger(other._callback_logger),
|
||||
_oss(std::move(other._oss)),
|
||||
_oss(),
|
||||
_level(other._level) {
|
||||
};
|
||||
|
||||
@@ -36,7 +40,7 @@ public:
|
||||
~line_logger() {
|
||||
if (_enabled) {
|
||||
_oss << '\n';
|
||||
_callback_logger->_log_it(_oss.str(), _level);
|
||||
_callback_logger->_log_it(_oss.str_ref(), _level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +54,8 @@ public:
|
||||
|
||||
private:
|
||||
logger* _callback_logger;
|
||||
std::ostringstream _oss;
|
||||
//std::ostringstream _oss;
|
||||
details::fast_oss _oss;
|
||||
level::level_enum _level;
|
||||
bool _enabled;
|
||||
|
||||
|
@@ -3,9 +3,12 @@
|
||||
#include<cstdio>
|
||||
#include<ctime>
|
||||
|
||||
namespace c11log {
|
||||
namespace details {
|
||||
namespace os {
|
||||
namespace c11log
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
namespace os
|
||||
{
|
||||
|
||||
inline std::tm localtime(const std::time_t &time_tt)
|
||||
{
|
||||
|
Reference in New Issue
Block a user