Added pattern formatter and updated related stuff
This commit is contained in:
		@@ -5,8 +5,10 @@
 | 
			
		||||
 | 
			
		||||
#include <ostream>
 | 
			
		||||
#include <iomanip>
 | 
			
		||||
#include "fast_istostr.h"
 | 
			
		||||
#include "stack_buf.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace c11log
 | 
			
		||||
{
 | 
			
		||||
namespace details
 | 
			
		||||
@@ -15,7 +17,7 @@ namespace details
 | 
			
		||||
class stack_devicebuf :public std::streambuf
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    static const unsigned short stack_size = 192;
 | 
			
		||||
    static const unsigned short stack_size = 256;
 | 
			
		||||
    using stackbuf_t = stack_buf<stack_size>;
 | 
			
		||||
 | 
			
		||||
    stack_devicebuf() = default;
 | 
			
		||||
@@ -103,6 +105,29 @@ public:
 | 
			
		||||
        _dev.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // The following were added because they add significant boost to perfromance
 | 
			
		||||
    void putc(char c)
 | 
			
		||||
    {
 | 
			
		||||
        _dev.sputc(c);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // put int and pad with zeroes if smalled than min_width
 | 
			
		||||
    void put_int(int n, int min_width)
 | 
			
		||||
    {
 | 
			
		||||
        std::string s;
 | 
			
		||||
        details::fast_itostr(n, s, min_width);
 | 
			
		||||
        _dev.sputn(s.data(), s.size());
 | 
			
		||||
        //sprintf_s(buf, "%d", n);
 | 
			
		||||
        //_dev.sputn(buf, width);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void put_str(const std::string& str)
 | 
			
		||||
    {
 | 
			
		||||
        _dev.sputn(str.data(), str.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    stack_devicebuf _dev;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -45,6 +45,7 @@ public:
 | 
			
		||||
        {
 | 
			
		||||
            _log_msg.logger_name = _callback_logger->name();
 | 
			
		||||
            _log_msg.time = log_clock::now();
 | 
			
		||||
            _log_msg.tm_time = details::os::localtime(log_clock::to_time_t(_log_msg.time));
 | 
			
		||||
            _log_msg.raw = _oss.str();
 | 
			
		||||
            _callback_logger->_log_msg(_log_msg);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@ struct log_msg
 | 
			
		||||
        logger_name(),
 | 
			
		||||
        level(l),
 | 
			
		||||
        time(),
 | 
			
		||||
        tm_time(),
 | 
			
		||||
        raw(),
 | 
			
		||||
        formatted() {}
 | 
			
		||||
 | 
			
		||||
@@ -21,6 +22,7 @@ struct log_msg
 | 
			
		||||
        logger_name(other.logger_name),
 | 
			
		||||
        level(other.level),
 | 
			
		||||
        time(other.time),
 | 
			
		||||
        tm_time(other.tm_time),
 | 
			
		||||
        raw(other.raw),
 | 
			
		||||
        formatted(other.formatted) {}
 | 
			
		||||
 | 
			
		||||
@@ -35,6 +37,7 @@ struct log_msg
 | 
			
		||||
        swap(l.logger_name, r.logger_name);
 | 
			
		||||
        swap(l.level, r.level);
 | 
			
		||||
        swap(l.time, r.time);
 | 
			
		||||
        swap(l.tm_time, r.tm_time);
 | 
			
		||||
        swap(l.raw, r.raw);
 | 
			
		||||
        swap(l.formatted, r.formatted);
 | 
			
		||||
    }
 | 
			
		||||
@@ -56,9 +59,11 @@ struct log_msg
 | 
			
		||||
    std::string logger_name;
 | 
			
		||||
    level::level_enum level;
 | 
			
		||||
    log_clock::time_point time;
 | 
			
		||||
    std::tm tm_time;
 | 
			
		||||
    std::string raw;
 | 
			
		||||
    std::string formatted;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user