Commit 32a8b51d authored by gabi's avatar gabi

pattern_formatter support most strftime format

parent 0c6a0d52
...@@ -17,16 +17,18 @@ int main(int argc, char* argv[]) ...@@ -17,16 +17,18 @@ int main(int argc, char* argv[])
{ {
const unsigned int howmany = argc <= 1 ? 500000 : atoi(argv[1]); const unsigned int howmany = argc <= 1 ? 500000 : atoi(argv[1]);
//std::string pattern = "%Y:%m:%d %H:%M:%S.%e ---> [%n:%l] %t"; //std::string pattern = "%B %d, %Y %H:%M:%S.%e **************[%n:%l] %t";
//auto formatter = std::make_shared<details::pattern_formatter>(pattern); std::string pattern = " [%z] %t";
auto formatter = std::make_shared<details::pattern_formatter>(pattern);
logger cout_logger("bench", { std::make_shared<sinks::stderr_sink_mt>() }); logger cout_logger("bench", { std::make_shared<sinks::stderr_sink_mt>() });
cout_logger.formatter(formatter);
cout_logger.info() << "Hello logger " << 1234; cout_logger.info() << "Hello logger " << 1234;
auto nullsink = std::make_shared<sinks::null_sink_st>(); auto nullsink = std::make_shared<sinks::null_sink_st>();
auto rotating = std::make_shared<sinks::rotating_file_sink_mt>("myrotating", "txt", 1024 * 1024 * 5, 5, 1); auto rotating = std::make_shared<sinks::rotating_file_sink_mt>("myrotating", "txt", 1024 * 1024 * 5, 5, 100);
logger my_logger("my_logger", { rotating }); logger my_logger("my_logger", { nullsink }, formatter);
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)
......
...@@ -26,7 +26,7 @@ inline std::string& fast_itostr(int n, std::string& s, int padding) ...@@ -26,7 +26,7 @@ inline std::string& fast_itostr(int n, std::string& s, int padding)
{ {
if (n == 0) if (n == 0)
{ {
s = "0"; s = std::string(padding, '0');
return s; return s;
} }
......
...@@ -143,6 +143,11 @@ public: ...@@ -143,6 +143,11 @@ public:
_dev.sputn(s.data(), s.size()); _dev.sputn(s.data(), s.size());
} }
void write_data(const char* p, std::size_t size)
{
_dev.sputn(p, size);
}
void write_str(const std::string& s) void write_str(const std::string& s)
{ {
_dev.sputn(s.data(), s.size()); _dev.sputn(s.data(), s.size());
......
#pragma once #pragma once
#include <sstream>
#include "../common.h" #include "../common.h"
#include "../logger.h" #include "../logger.h"
#include "fast_oss.h" #include "./fast_oss.h"
// Line logger class - aggregates operator<< calls to fast ostream // Line logger class - aggregates operator<< calls to fast ostream
......
#pragma once #pragma once
#include "../common.h" #include "../common.h"
#include "fast_oss.h" #include "./fast_oss.h"
namespace c11log namespace c11log
{ {
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include<string> #include<string>
#include<cstdio> #include<cstdio>
#include<ctime> #include<ctime>
#ifdef _WIN32
#include <Windows.h>
#endif
namespace c11log namespace c11log
{ {
...@@ -81,6 +84,17 @@ inline bool fopen_s(FILE** fp, const std::string& filename, const char* mode) ...@@ -81,6 +84,17 @@ inline bool fopen_s(FILE** fp, const std::string& filename, const char* mode)
#endif #endif
} }
inline float tz_offset()
{
#ifdef _WIN32
TIME_ZONE_INFORMATION tzinfo;
GetTimeZoneInformation(&tzinfo);
return tzinfo.Bias / -60.0f;
#else
return 0.0f;
#endif
}
} //os } //os
} //details } //details
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <atomic> #include <atomic>
#include <algorithm> #include <algorithm>
#include "base_sink.h" #include "./base_sink.h"
#include "../logger.h" #include "../logger.h"
#include "../details/blocking_queue.h" #include "../details/blocking_queue.h"
#include "../details/null_mutex.h" #include "../details/null_mutex.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include<string> #include<string>
#include<mutex> #include<mutex>
#include<atomic> #include<atomic>
#include "sink.h" #include "./sink.h"
#include "../formatter.h" #include "../formatter.h"
#include "../common.h" #include "../common.h"
#include "../details/log_msg.h" #include "../details/log_msg.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include "base_sink.h" #include "./base_sink.h"
#include <mutex> #include <mutex>
#include "../details/null_mutex.h" #include "../details/null_mutex.h"
#include "../details/flush_helper.h" #include "../details/flush_helper.h"
......
#pragma once #pragma once
#include <mutex> #include <mutex>
#include "base_sink.h" #include "./base_sink.h"
#include "../details/null_mutex.h" #include "../details/null_mutex.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <memory> #include <memory>
#include "../details/null_mutex.h" #include "../details/null_mutex.h"
#include "base_sink.h" #include "./base_sink.h"
namespace c11log namespace c11log
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include "ostream_sink.h" #include "./ostream_sink.h"
#include "../details/null_mutex.h" #include "../details/null_mutex.h"
namespace c11log namespace c11log
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment