mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
1. renamed lib to to spitlog
2. Rotating bugfix
This commit is contained in:
parent
cda4b9b4d5
commit
cbddc8796a
@ -1,27 +1,27 @@
|
|||||||
========================================================================
|
========================================================================
|
||||||
CONSOLE APPLICATION : c11logtest Project Overview
|
CONSOLE APPLICATION : spitlogtest Project Overview
|
||||||
========================================================================
|
========================================================================
|
||||||
|
|
||||||
AppWizard has created this c11logtest application for you.
|
AppWizard has created this spitlogtest application for you.
|
||||||
|
|
||||||
This file contains a summary of what you will find in each of the files that
|
This file contains a summary of what you will find in each of the files that
|
||||||
make up your c11logtest application.
|
make up your spitlogtest application.
|
||||||
|
|
||||||
|
|
||||||
c11logtest.vcxproj
|
spitlogtest.vcxproj
|
||||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||||
It contains information about the version of Visual C++ that generated the file, and
|
It contains information about the version of Visual C++ that generated the file, and
|
||||||
information about the platforms, configurations, and project features selected with the
|
information about the platforms, configurations, and project features selected with the
|
||||||
Application Wizard.
|
Application Wizard.
|
||||||
|
|
||||||
c11logtest.vcxproj.filters
|
spitlogtest.vcxproj.filters
|
||||||
This is the filters file for VC++ projects generated using an Application Wizard.
|
This is the filters file for VC++ projects generated using an Application Wizard.
|
||||||
It contains information about the association between the files in your project
|
It contains information about the association between the files in your project
|
||||||
and the filters. This association is used in the IDE to show grouping of files with
|
and the filters. This association is used in the IDE to show grouping of files with
|
||||||
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
|
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
|
||||||
"Source Files" filter).
|
"Source Files" filter).
|
||||||
|
|
||||||
c11logtest.cpp
|
spitlogtest.cpp
|
||||||
This is the main application source file.
|
This is the main application source file.
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
@ -29,7 +29,7 @@ Other standard files:
|
|||||||
|
|
||||||
StdAfx.h, StdAfx.cpp
|
StdAfx.h, StdAfx.cpp
|
||||||
These files are used to build a precompiled header (PCH) file
|
These files are used to build a precompiled header (PCH) file
|
||||||
named c11logtest.pch and a precompiled types file named StdAfx.obj.
|
named spitlogtest.pch and a precompiled types file named StdAfx.obj.
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
Other notes:
|
Other notes:
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{DC7F2F3E-0D0E-4324-A278-410DBC4045AD}</ProjectGuid>
|
<ProjectGuid>{DC7F2F3E-0D0E-4324-A278-410DBC4045AD}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>c11logtest</RootNamespace>
|
<RootNamespace>spitlogtest</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
@ -52,7 +52,7 @@
|
|||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>../../include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>E:\devel\c11log\example;../../include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -69,7 +69,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>../../include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>E:\devel\c11log\example;../../include</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -85,28 +85,28 @@
|
|||||||
<Text Include="ReadMe.txt" />
|
<Text Include="ReadMe.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\include\c11log\common.h" />
|
<ClInclude Include="..\..\include\spitlog\common.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\blocking_queue.h" />
|
<ClInclude Include="..\..\include\spitlog\details\blocking_queue.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\fast_oss.h" />
|
<ClInclude Include="..\..\include\spitlog\details\fast_oss.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\fast_istostr.h" />
|
<ClInclude Include="..\..\include\spitlog\details\fast_istostr.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\file_helper.h" />
|
<ClInclude Include="..\..\include\spitlog\details\file_helper.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\line_logger.h" />
|
<ClInclude Include="..\..\include\spitlog\details\line_logger.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\logger_impl.h" />
|
<ClInclude Include="..\..\include\spitlog\details\logger_impl.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\log_msg.h" />
|
<ClInclude Include="..\..\include\spitlog\details\log_msg.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\null_mutex.h" />
|
<ClInclude Include="..\..\include\spitlog\details\null_mutex.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\os.h" />
|
<ClInclude Include="..\..\include\spitlog\details\os.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\pattern_formatter_impl.h" />
|
<ClInclude Include="..\..\include\spitlog\details\pattern_formatter_impl.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\registry.h" />
|
<ClInclude Include="..\..\include\spitlog\details\registry.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\details\stack_buf.h" />
|
<ClInclude Include="..\..\include\spitlog\details\stack_buf.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\formatter.h" />
|
<ClInclude Include="..\..\include\spitlog\formatter.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\logger.h" />
|
<ClInclude Include="..\..\include\spitlog\logger.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\async_sink.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\async_sink.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\base_sink.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\base_sink.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\ostream_sink.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\ostream_sink.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\file_sinks.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\file_sinks.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\null_sink.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\null_sink.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\sink.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\sink.h" />
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\stdout_sinks.h" />
|
<ClInclude Include="..\..\include\spitlog\sinks\stdout_sinks.h" />
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -33,71 +33,71 @@
|
|||||||
<ClInclude Include="targetver.h">
|
<ClInclude Include="targetver.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\formatter.h">
|
<ClInclude Include="..\..\include\spitlog\common.h">
|
||||||
<Filter>Header Files\c11log</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\logger.h">
|
<ClInclude Include="..\..\include\spitlog\details\blocking_queue.h">
|
||||||
<Filter>Header Files\c11log</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\blocking_queue.h">
|
<ClInclude Include="..\..\include\spitlog\details\fast_oss.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\fast_oss.h">
|
<ClInclude Include="..\..\include\spitlog\details\fast_istostr.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\line_logger.h">
|
<ClInclude Include="..\..\include\spitlog\details\file_helper.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\log_msg.h">
|
<ClInclude Include="..\..\include\spitlog\details\line_logger.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\os.h">
|
<ClInclude Include="..\..\include\spitlog\details\logger_impl.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\stack_buf.h">
|
<ClInclude Include="..\..\include\spitlog\details\log_msg.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\async_sink.h">
|
<ClInclude Include="..\..\include\spitlog\details\null_mutex.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\base_sink.h">
|
<ClInclude Include="..\..\include\spitlog\details\os.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\file_sinks.h">
|
<ClInclude Include="..\..\include\spitlog\details\pattern_formatter_impl.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\null_mutex.h">
|
<ClInclude Include="..\..\include\spitlog\details\registry.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\null_sink.h">
|
<ClInclude Include="..\..\include\spitlog\details\stack_buf.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\ostream_sink.h">
|
<ClInclude Include="..\..\include\spitlog\formatter.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\stdout_sinks.h">
|
<ClInclude Include="..\..\include\spitlog\logger.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\common.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\async_sink.h">
|
||||||
<Filter>Header Files\c11log</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\fast_istostr.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\base_sink.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\sinks\sink.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\ostream_sink.h">
|
||||||
<Filter>Header Files\c11log\sinks</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\pattern_formatter_impl.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\file_sinks.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\logger_impl.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\null_sink.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\registry.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\sink.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\c11log\details\file_helper.h">
|
<ClInclude Include="..\..\include\spitlog\sinks\stdout_sinks.h">
|
||||||
<Filter>Header Files\c11log\details</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// stdafx.cpp : source file that includes just the standard includes
|
// stdafx.cpp : source file that includes just the standard includes
|
||||||
// c11logtest.pch will be the pre-compiled header
|
// spitlogtest.pch will be the pre-compiled header
|
||||||
// stdafx.obj will contain the pre-compiled type information
|
// stdafx.obj will contain the pre-compiled type information
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
// example.cpp : Simple logger example
|
// example.cpp : Simple logger example
|
||||||
//
|
//
|
||||||
#include "c11log/logger.h"
|
#include "spitlog/logger.h"
|
||||||
#include "c11log/sinks/async_sink.h"
|
#include "spitlog/sinks/async_sink.h"
|
||||||
#include "c11log/sinks/file_sinks.h"
|
#include "spitlog/sinks/file_sinks.h"
|
||||||
#include "c11log/sinks/stdout_sinks.h"
|
#include "spitlog/sinks/stdout_sinks.h"
|
||||||
#include "c11log/sinks/null_sink.h"
|
#include "spitlog/sinks/null_sink.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "c11log/details/registry.h"
|
#include "spitlog/details/registry.h"
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using namespace c11log;
|
using namespace spitlog;
|
||||||
using namespace utils;
|
using namespace utils;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const unsigned int howmany = argc <= 1 ? 500000 : atoi(argv[1]);
|
const unsigned int howmany = argc <= 1 ? 1500000 : atoi(argv[1]);
|
||||||
|
|
||||||
//c11log::set_format("%t");
|
//spitlog::set_format("%t");
|
||||||
auto console = c11log::create<sinks::stdout_sink_st>("reporter");
|
auto console = spitlog::create<sinks::stdout_sink_st>("reporter");
|
||||||
//console->set_format("[%n %l] %t");
|
//console->set_format("[%n %l] %t");
|
||||||
console->set_level(c11log::level::INFO);
|
console->set_level(spitlog::level::INFO);
|
||||||
console->info("Starting bench with", howmany, "iterations..");
|
console->info("Starting bench with", howmany, "iterations..");
|
||||||
|
|
||||||
auto bench = c11log::create<sinks::rotating_file_sink_st>("bench", "myrotating", "txt", 1024 * 1024 * 1, 3, 0);
|
auto bench = spitlog::create<sinks::rotating_file_sink_st>("bench", "myrotating", "txt", 1024 * 1024 * 1, 10, 0);
|
||||||
|
|
||||||
//auto bench = c11log::create<sinks::simple_file_sink_st>("bench", "simplelog.txt", 1);
|
//auto bench = spitlog::create<sinks::simple_file_sink_st>("bench", "simplelog.txt", 1);
|
||||||
//auto bench = c11log::create<sinks::null_sink_st>("bench");
|
//auto bench = spitlog::create<sinks::null_sink_st>("bench");
|
||||||
auto start = system_clock::now();
|
auto start = system_clock::now();
|
||||||
for (unsigned int i = 0; i < howmany; ++i)
|
for (unsigned int i = 0; i < howmany; ++i)
|
||||||
{
|
{
|
||||||
@ -45,6 +45,7 @@ int main(int argc, char* argv[])
|
|||||||
catch (std::exception &ex)
|
catch (std::exception &ex)
|
||||||
{
|
{
|
||||||
std::cerr << "Exception: " << ex.what() << std::endl;
|
std::cerr << "Exception: " << ex.what() << std::endl;
|
||||||
|
perror("Last error");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
#define FFLOG_ENABLE_TRACE
|
#define FFLOG_ENABLE_TRACE
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "c11log/logger.h"
|
#include "spitlog/logger.h"
|
||||||
#include "c11log/sinks/stdout_sinks.h"
|
#include "spitlog/sinks/stdout_sinks.h"
|
||||||
#include "c11log/sinks/file_sinks.h"
|
#include "spitlog/sinks/file_sinks.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace c11log;
|
using namespace spitlog;
|
||||||
|
|
||||||
|
|
||||||
details::fast_oss f(const std::string& what)
|
details::fast_oss f(const std::string& what)
|
||||||
|
@ -1,163 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
//
|
|
||||||
// Logger implementation
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "./line_logger.h"
|
|
||||||
|
|
||||||
|
|
||||||
inline c11log::logger::logger(const std::string& logger_name, sinks_init_list sinks_list) :
|
|
||||||
_name(logger_name),
|
|
||||||
_sinks(sinks_list)
|
|
||||||
{
|
|
||||||
// no support under vs2013 for member initialization for std::atomic
|
|
||||||
_level = level::INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class It>
|
|
||||||
inline c11log::logger::logger(const std::string& logger_name, const It& begin, const It& end) :
|
|
||||||
_name(logger_name),
|
|
||||||
_sinks(begin, end)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
inline void c11log::logger::set_formatter(c11log::formatter_ptr msg_formatter)
|
|
||||||
{
|
|
||||||
_formatter = msg_formatter;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void c11log::logger::set_format(const std::string& format)
|
|
||||||
{
|
|
||||||
_formatter = std::make_shared<pattern_formatter>(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline c11log::formatter_ptr c11log::logger::get_formatter() const
|
|
||||||
{
|
|
||||||
return _formatter;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::log(level::level_enum lvl, const Args&... args) {
|
|
||||||
bool msg_enabled = should_log(lvl);
|
|
||||||
details::line_logger l(this, lvl, msg_enabled);
|
|
||||||
if (msg_enabled)
|
|
||||||
_variadic_log(l, args...);
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::trace(const Args&... args)
|
|
||||||
{
|
|
||||||
return log(level::TRACE, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::debug(const Args&... args)
|
|
||||||
{
|
|
||||||
return log(level::DEBUG, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::info(const Args&... args)
|
|
||||||
{
|
|
||||||
return log(level::INFO, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::warn(const Args&... args)
|
|
||||||
{
|
|
||||||
return log(level::WARN, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::error(const Args&... args)
|
|
||||||
{
|
|
||||||
return log(level::ERR, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
inline c11log::details::line_logger c11log::logger::critical(const Args&... args)
|
|
||||||
{
|
|
||||||
return log(level::CRITICAL, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const std::string& c11log::logger::name() const
|
|
||||||
{
|
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void c11log::logger::set_level(c11log::level::level_enum log_level)
|
|
||||||
{
|
|
||||||
_level.store(log_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline c11log::level::level_enum c11log::logger::level() const
|
|
||||||
{
|
|
||||||
return static_cast<c11log::level::level_enum>(_level.load());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool c11log::logger::should_log(c11log::level::level_enum msg_level) const
|
|
||||||
{
|
|
||||||
return msg_level >= _level.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void c11log::logger::_variadic_log(c11log::details::line_logger&) {}
|
|
||||||
|
|
||||||
template <typename First, typename... Rest>
|
|
||||||
void c11log::logger::_variadic_log(c11log::details::line_logger& l, const First& first, const Rest&... rest)
|
|
||||||
{
|
|
||||||
l.write(first);
|
|
||||||
l.write(' ');
|
|
||||||
_variadic_log(l, rest...);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void c11log::logger::_log_msg(details::log_msg& msg)
|
|
||||||
{
|
|
||||||
//Use default formatter if not set
|
|
||||||
if (!_formatter)
|
|
||||||
_formatter = std::make_shared<pattern_formatter>("%+");
|
|
||||||
_formatter->format(msg);
|
|
||||||
for (auto &sink : _sinks)
|
|
||||||
sink->log(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Global registry functions
|
|
||||||
//
|
|
||||||
#include "./registry.h"
|
|
||||||
inline std::shared_ptr<c11log::logger> c11log::get(const std::string& name)
|
|
||||||
{
|
|
||||||
return details::registry::instance().get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::shared_ptr<c11log::logger> c11log::create(const std::string& logger_name, c11log::sinks_init_list sinks)
|
|
||||||
{
|
|
||||||
return details::registry::instance().create(logger_name, sinks);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename Sink, typename... Args>
|
|
||||||
inline std::shared_ptr<c11log::logger> c11log::create(const std::string& logger_name, const Args&... args)
|
|
||||||
{
|
|
||||||
sink_ptr sink = std::make_shared<Sink>(args...);
|
|
||||||
return details::registry::instance().create(logger_name, { sink });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class It>
|
|
||||||
inline std::shared_ptr<c11log::logger> c11log::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
|
|
||||||
{
|
|
||||||
return details::registry::instance().create(logger_name, std::forward(sinks_begin), std::forward(sinks_end));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void c11log::set_formatter(c11log::formatter_ptr f)
|
|
||||||
{
|
|
||||||
details::registry::instance().formatter(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void c11log::set_format(const std::string& format_string)
|
|
||||||
{
|
|
||||||
return details::registry::instance().set_format(format_string);
|
|
||||||
}
|
|
@ -3,7 +3,7 @@
|
|||||||
#include<initializer_list>
|
#include<initializer_list>
|
||||||
#include<chrono>
|
#include<chrono>
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
class formatter;
|
class formatter;
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
@ -14,7 +14,7 @@ class sink;
|
|||||||
using log_clock = std::chrono::system_clock;
|
using log_clock = std::chrono::system_clock;
|
||||||
using sink_ptr = std::shared_ptr < sinks::sink > ;
|
using sink_ptr = std::shared_ptr < sinks::sink > ;
|
||||||
using sinks_init_list = std::initializer_list < sink_ptr > ;
|
using sinks_init_list = std::initializer_list < sink_ptr > ;
|
||||||
using formatter_ptr = std::shared_ptr<c11log::formatter>;
|
using formatter_ptr = std::shared_ptr<spitlog::formatter>;
|
||||||
|
|
||||||
//Log level enum
|
//Log level enum
|
||||||
namespace level
|
namespace level
|
||||||
@ -31,7 +31,7 @@ typedef enum
|
|||||||
} level_enum;
|
} level_enum;
|
||||||
|
|
||||||
static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "fatal" };
|
static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "fatal" };
|
||||||
inline const char* to_str(c11log::level::level_enum l)
|
inline const char* to_str(spitlog::level::level_enum l)
|
||||||
{
|
{
|
||||||
return level_names[l];
|
return level_names[l];
|
||||||
}
|
}
|
||||||
@ -52,4 +52,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //c11log
|
} //spitlog
|
@ -10,7 +10,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
@ -5,7 +5,7 @@
|
|||||||
//Source: http://stackoverflow.com/a/4351484/192001
|
//Source: http://stackoverflow.com/a/4351484/192001
|
||||||
//Modified version to pad zeros according to padding arg
|
//Modified version to pad zeros according to padding arg
|
||||||
|
|
||||||
namespace c11log {
|
namespace spitlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
const char digit_pairs[201] = {
|
const char digit_pairs[201] = {
|
@ -9,7 +9,7 @@
|
|||||||
#include "stack_buf.h"
|
#include "stack_buf.h"
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ public:
|
|||||||
auto& buf = msg.formatted.buf();
|
auto& buf = msg.formatted.buf();
|
||||||
size_t size = buf.size();
|
size_t size = buf.size();
|
||||||
if(std::fwrite(buf.data(), sizeof(char), size, _fd) != size)
|
if(std::fwrite(buf.data(), sizeof(char), size, _fd) != size)
|
||||||
throw fflog_exception("Failed writing to file " + _filename);
|
throw fflog_exception("Failed writing to file " + _filename);
|
||||||
|
|
||||||
if(--_flush_countdown == 0)
|
if(--_flush_countdown == 0)
|
||||||
{
|
{
|
||||||
@ -79,6 +79,25 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& filename() const
|
||||||
|
{
|
||||||
|
return _filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool file_exists(const std::string& name)
|
||||||
|
{
|
||||||
|
FILE* file;
|
||||||
|
if (!os::fopen_s(&file, name.c_str(), "r"))
|
||||||
|
{
|
||||||
|
fclose(file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE* _fd;
|
FILE* _fd;
|
||||||
std::string _filename;
|
std::string _filename;
|
@ -8,7 +8,7 @@
|
|||||||
// Line logger class - aggregates operator<< calls to fast ostream
|
// Line logger class - aggregates operator<< calls to fast ostream
|
||||||
// and logs upon destruction
|
// and logs upon destruction
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
||||||
@ -76,4 +76,4 @@ private:
|
|||||||
bool _enabled;
|
bool _enabled;
|
||||||
};
|
};
|
||||||
} //Namespace details
|
} //Namespace details
|
||||||
} // Namespace c11log
|
} // Namespace spitlog
|
@ -3,7 +3,7 @@
|
|||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "./fast_oss.h"
|
#include "./fast_oss.h"
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
163
include/spitlog/details/logger_impl.h
Normal file
163
include/spitlog/details/logger_impl.h
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
#pragma once
|
||||||
|
//
|
||||||
|
// Logger implementation
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include "./line_logger.h"
|
||||||
|
|
||||||
|
|
||||||
|
inline spitlog::logger::logger(const std::string& logger_name, sinks_init_list sinks_list) :
|
||||||
|
_name(logger_name),
|
||||||
|
_sinks(sinks_list)
|
||||||
|
{
|
||||||
|
// no support under vs2013 for member initialization for std::atomic
|
||||||
|
_level = level::INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class It>
|
||||||
|
inline spitlog::logger::logger(const std::string& logger_name, const It& begin, const It& end) :
|
||||||
|
_name(logger_name),
|
||||||
|
_sinks(begin, end)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline void spitlog::logger::set_formatter(spitlog::formatter_ptr msg_formatter)
|
||||||
|
{
|
||||||
|
_formatter = msg_formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void spitlog::logger::set_format(const std::string& format)
|
||||||
|
{
|
||||||
|
_formatter = std::make_shared<pattern_formatter>(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline spitlog::formatter_ptr spitlog::logger::get_formatter() const
|
||||||
|
{
|
||||||
|
return _formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::log(level::level_enum lvl, const Args&... args) {
|
||||||
|
bool msg_enabled = should_log(lvl);
|
||||||
|
details::line_logger l(this, lvl, msg_enabled);
|
||||||
|
if (msg_enabled)
|
||||||
|
_variadic_log(l, args...);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::trace(const Args&... args)
|
||||||
|
{
|
||||||
|
return log(level::TRACE, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::debug(const Args&... args)
|
||||||
|
{
|
||||||
|
return log(level::DEBUG, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::info(const Args&... args)
|
||||||
|
{
|
||||||
|
return log(level::INFO, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::warn(const Args&... args)
|
||||||
|
{
|
||||||
|
return log(level::WARN, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::error(const Args&... args)
|
||||||
|
{
|
||||||
|
return log(level::ERR, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
inline spitlog::details::line_logger spitlog::logger::critical(const Args&... args)
|
||||||
|
{
|
||||||
|
return log(level::CRITICAL, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const std::string& spitlog::logger::name() const
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void spitlog::logger::set_level(spitlog::level::level_enum log_level)
|
||||||
|
{
|
||||||
|
_level.store(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline spitlog::level::level_enum spitlog::logger::level() const
|
||||||
|
{
|
||||||
|
return static_cast<spitlog::level::level_enum>(_level.load());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool spitlog::logger::should_log(spitlog::level::level_enum msg_level) const
|
||||||
|
{
|
||||||
|
return msg_level >= _level.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void spitlog::logger::_variadic_log(spitlog::details::line_logger&) {}
|
||||||
|
|
||||||
|
template <typename First, typename... Rest>
|
||||||
|
void spitlog::logger::_variadic_log(spitlog::details::line_logger& l, const First& first, const Rest&... rest)
|
||||||
|
{
|
||||||
|
l.write(first);
|
||||||
|
l.write(' ');
|
||||||
|
_variadic_log(l, rest...);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void spitlog::logger::_log_msg(details::log_msg& msg)
|
||||||
|
{
|
||||||
|
//Use default formatter if not set
|
||||||
|
if (!_formatter)
|
||||||
|
_formatter = std::make_shared<pattern_formatter>("%+");
|
||||||
|
_formatter->format(msg);
|
||||||
|
for (auto &sink : _sinks)
|
||||||
|
sink->log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Global registry functions
|
||||||
|
//
|
||||||
|
#include "./registry.h"
|
||||||
|
inline std::shared_ptr<spitlog::logger> spitlog::get(const std::string& name)
|
||||||
|
{
|
||||||
|
return details::registry::instance().get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::shared_ptr<spitlog::logger> spitlog::create(const std::string& logger_name, spitlog::sinks_init_list sinks)
|
||||||
|
{
|
||||||
|
return details::registry::instance().create(logger_name, sinks);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Sink, typename... Args>
|
||||||
|
inline std::shared_ptr<spitlog::logger> spitlog::create(const std::string& logger_name, const Args&... args)
|
||||||
|
{
|
||||||
|
sink_ptr sink = std::make_shared<Sink>(args...);
|
||||||
|
return details::registry::instance().create(logger_name, { sink });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class It>
|
||||||
|
inline std::shared_ptr<spitlog::logger> spitlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
|
||||||
|
{
|
||||||
|
return details::registry::instance().create(logger_name, std::forward(sinks_begin), std::forward(sinks_end));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void spitlog::set_formatter(spitlog::formatter_ptr f)
|
||||||
|
{
|
||||||
|
details::registry::instance().formatter(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void spitlog::set_format(const std::string& format_string)
|
||||||
|
{
|
||||||
|
return details::registry::instance().set_format(format_string);
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// null, no cost mutex
|
// null, no cost mutex
|
||||||
|
|
||||||
namespace c11log {
|
namespace spitlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
struct null_mutex
|
struct null_mutex
|
||||||
{
|
{
|
@ -7,7 +7,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
||||||
@ -123,7 +123,7 @@ inline int utc_minutes_offset(const std::tm& tm = localtime())
|
|||||||
|
|
||||||
} //os
|
} //os
|
||||||
} //details
|
} //details
|
||||||
} //c11log
|
} //spitlog
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
|||||||
#include "./fast_oss.h"
|
#include "./fast_oss.h"
|
||||||
#include "./os.h"
|
#include "./os.h"
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details {
|
namespace details {
|
||||||
class flag_formatter
|
class flag_formatter
|
||||||
@ -377,12 +377,12 @@ class full_formatter :public flag_formatter
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// pattern_formatter inline impl
|
// pattern_formatter inline impl
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
inline c11log::pattern_formatter::pattern_formatter(const std::string& pattern)
|
inline spitlog::pattern_formatter::pattern_formatter(const std::string& pattern)
|
||||||
{
|
{
|
||||||
compile_pattern(pattern);
|
compile_pattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void c11log::pattern_formatter::compile_pattern(const std::string& pattern)
|
inline void spitlog::pattern_formatter::compile_pattern(const std::string& pattern)
|
||||||
{
|
{
|
||||||
auto end = pattern.end();
|
auto end = pattern.end();
|
||||||
std::unique_ptr<details::aggregate_formatter> user_chars;
|
std::unique_ptr<details::aggregate_formatter> user_chars;
|
||||||
@ -411,7 +411,7 @@ inline void c11log::pattern_formatter::compile_pattern(const std::string& patter
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
inline void c11log::pattern_formatter::handle_flag(char flag)
|
inline void spitlog::pattern_formatter::handle_flag(char flag)
|
||||||
{
|
{
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
@ -523,7 +523,7 @@ inline void c11log::pattern_formatter::handle_flag(char flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void c11log::pattern_formatter::format(details::log_msg& msg)
|
inline void spitlog::pattern_formatter::format(details::log_msg& msg)
|
||||||
{
|
{
|
||||||
for (auto &f : _formatters)
|
for (auto &f : _formatters)
|
||||||
{
|
{
|
@ -10,7 +10,7 @@
|
|||||||
#include "../logger.h"
|
#include "../logger.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
namespace c11log {
|
namespace spitlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
class registry {
|
class registry {
|
||||||
public:
|
public:
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// Fast memory storage on the stack when possible or in std::vector
|
// Fast memory storage on the stack when possible or in std::vector
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details
|
namespace details
|
||||||
{
|
{
|
||||||
@ -108,4 +108,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
} //namespace c11log { namespace details {
|
} //namespace spitlog { namespace details {
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "details/log_msg.h"
|
#include "details/log_msg.h"
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace details {
|
namespace details {
|
||||||
class flag_formatter;
|
class flag_formatter;
|
@ -15,7 +15,7 @@
|
|||||||
#include "sinks/base_sink.h"
|
#include "sinks/base_sink.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace details
|
namespace details
|
||||||
@ -70,14 +70,14 @@ private:
|
|||||||
//
|
//
|
||||||
// Registry functions for easy loggers creation and retrieval
|
// Registry functions for easy loggers creation and retrieval
|
||||||
// example
|
// example
|
||||||
// auto console_logger = c11log::create("my_logger", c11log::sinks<stdout_sink_mt>);
|
// auto console_logger = spitlog::create("my_logger", spitlog::sinks<stdout_sink_mt>);
|
||||||
// auto same_logger = c11log::get("my_logger");
|
// auto same_logger = spitlog::get("my_logger");
|
||||||
// auto file_logger = c11
|
// auto file_logger = c11
|
||||||
//
|
//
|
||||||
std::shared_ptr<logger> get(const std::string& name);
|
std::shared_ptr<logger> get(const std::string& name);
|
||||||
std::shared_ptr<logger> create(const std::string& logger_name, sinks_init_list sinks);
|
std::shared_ptr<logger> create(const std::string& logger_name, sinks_init_list sinks);
|
||||||
template <typename Sink, typename... Args>
|
template <typename Sink, typename... Args>
|
||||||
std::shared_ptr<c11log::logger> create(const std::string& logger_name, const Args&... args);
|
std::shared_ptr<spitlog::logger> create(const std::string& logger_name, const Args&... args);
|
||||||
template<class It>
|
template<class It>
|
||||||
std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end);
|
std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end);
|
||||||
|
|
||||||
@ -89,13 +89,13 @@ void set_format(const std::string& format_string);
|
|||||||
// Trace & debug macros
|
// Trace & debug macros
|
||||||
//
|
//
|
||||||
#ifdef FFLOG_ENABLE_TRACE
|
#ifdef FFLOG_ENABLE_TRACE
|
||||||
#define FFLOG_TRACE(logger, ...) logger->log(c11log::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
|
#define FFLOG_TRACE(logger, ...) logger->log(spitlog::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define FFLOG_TRACE(logger, ...) {}
|
#define FFLOG_TRACE(logger, ...) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FFLOG_ENABLE_DEBUG
|
#ifdef FFLOG_ENABLE_DEBUG
|
||||||
#define FFLOG_DEBUG(logger, ...) logger->log(c11log::level::DEBUG, __VA_ARGS__)
|
#define FFLOG_DEBUG(logger, ...) logger->log(spitlog::level::DEBUG, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define FFLOG_DEBUG(logger, ...) {}
|
#define FFLOG_DEBUG(logger, ...) {}
|
||||||
#endif
|
#endif
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
||||||
@ -53,26 +53,26 @@ private:
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// async_sink class implementation
|
// async_sink class implementation
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
inline c11log::sinks::async_sink::async_sink(const q_type::size_type max_queue_size)
|
inline spitlog::sinks::async_sink::async_sink(const q_type::size_type max_queue_size)
|
||||||
:_sinks(),
|
:_sinks(),
|
||||||
_active(true),
|
_active(true),
|
||||||
_q(max_queue_size),
|
_q(max_queue_size),
|
||||||
_back_thread(&async_sink::_thread_loop, this)
|
_back_thread(&async_sink::_thread_loop, this)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline c11log::sinks::async_sink::~async_sink()
|
inline spitlog::sinks::async_sink::~async_sink()
|
||||||
{
|
{
|
||||||
_shutdown();
|
_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
|
inline void spitlog::sinks::async_sink::_sink_it(const details::log_msg& msg)
|
||||||
{
|
{
|
||||||
if(!_active)
|
if(!_active)
|
||||||
return;
|
return;
|
||||||
_q.push(msg);
|
_q.push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void c11log::sinks::async_sink::_thread_loop()
|
inline void spitlog::sinks::async_sink::_thread_loop()
|
||||||
{
|
{
|
||||||
static std::chrono::seconds pop_timeout { 1 };
|
static std::chrono::seconds pop_timeout { 1 };
|
||||||
while (_active)
|
while (_active)
|
||||||
@ -90,27 +90,27 @@ inline void c11log::sinks::async_sink::_thread_loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void c11log::sinks::async_sink::add_sink(c11log::sink_ptr s)
|
inline void spitlog::sinks::async_sink::add_sink(spitlog::sink_ptr s)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(_mutex);
|
std::lock_guard<std::mutex> guard(_mutex);
|
||||||
_sinks.push_back(s);
|
_sinks.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void c11log::sinks::async_sink::remove_sink(c11log::sink_ptr s)
|
inline void spitlog::sinks::async_sink::remove_sink(spitlog::sink_ptr s)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(_mutex);
|
std::lock_guard<std::mutex> guard(_mutex);
|
||||||
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), s), _sinks.end());
|
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), s), _sinks.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline c11log::sinks::async_sink::q_type& c11log::sinks::async_sink::q()
|
inline spitlog::sinks::async_sink::q_type& spitlog::sinks::async_sink::q()
|
||||||
{
|
{
|
||||||
return _q;
|
return _q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
|
inline void spitlog::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
|
||||||
{
|
{
|
||||||
if(timeout > std::chrono::milliseconds::zero())
|
if(timeout > std::chrono::milliseconds::zero())
|
||||||
{
|
{
|
||||||
@ -124,7 +124,7 @@ inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds&
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void c11log::sinks::async_sink::_shutdown()
|
inline void spitlog::sinks::async_sink::_shutdown()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(_mutex);
|
std::lock_guard<std::mutex> guard(_mutex);
|
||||||
if(_active)
|
if(_active)
|
@ -14,7 +14,7 @@
|
|||||||
#include "../details/log_msg.h"
|
#include "../details/log_msg.h"
|
||||||
|
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "./base_sink.h"
|
#include "./base_sink.h"
|
||||||
|
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "../details/file_helper.h"
|
#include "../details/file_helper.h"
|
||||||
|
#include "../details/fast_oss.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
||||||
@ -56,7 +57,7 @@ public:
|
|||||||
_current_size(0),
|
_current_size(0),
|
||||||
_file_helper(flush_inverval)
|
_file_helper(flush_inverval)
|
||||||
{
|
{
|
||||||
_file_helper.open(_calc_filename(_base_filename, 0, _extension));
|
_file_helper.open(calc_filename(_base_filename, 0, _extension));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -73,9 +74,9 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string _calc_filename(const std::string& filename, std::size_t index, const std::string& extension)
|
static std::string calc_filename(const std::string& filename, std::size_t index, const std::string& extension)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
details::fast_oss oss;
|
||||||
if (index)
|
if (index)
|
||||||
oss << filename << "." << index << "." << extension;
|
oss << filename << "." << index << "." << extension;
|
||||||
else
|
else
|
||||||
@ -96,11 +97,19 @@ private:
|
|||||||
_file_helper.close();
|
_file_helper.close();
|
||||||
for (auto i = _max_files; i > 0; --i)
|
for (auto i = _max_files; i > 0; --i)
|
||||||
{
|
{
|
||||||
std::string src = _calc_filename(_base_filename, i - 1, _extension);
|
std::string src = calc_filename(_base_filename, i - 1, _extension);
|
||||||
std::string target = _calc_filename(_base_filename, i, _extension);
|
std::string target = calc_filename(_base_filename, i, _extension);
|
||||||
std::rename(src.c_str(), target.c_str());
|
|
||||||
|
if (details::file_helper::file_exists(target))
|
||||||
|
std::remove(target.c_str());
|
||||||
|
if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str()))
|
||||||
|
{
|
||||||
|
throw fflog_exception("rotating_file_sink: failed renaming " + src + " to " + target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_file_helper.open(_calc_filename(_base_filename, 0, _extension));
|
auto cur_name = _file_helper.filename();
|
||||||
|
std::remove(cur_name.c_str());
|
||||||
|
_file_helper.open(cur_name);
|
||||||
}
|
}
|
||||||
std::string _base_filename;
|
std::string _base_filename;
|
||||||
std::string _extension;
|
std::string _extension;
|
||||||
@ -128,7 +137,7 @@ public:
|
|||||||
_midnight_tp (_calc_midnight_tp() ),
|
_midnight_tp (_calc_midnight_tp() ),
|
||||||
_file_helper(flush_inverval)
|
_file_helper(flush_inverval)
|
||||||
{
|
{
|
||||||
_file_helper.open(_calc_filename(_base_filename, _extension));
|
_file_helper.open(calc_filename(_base_filename, _extension));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -137,7 +146,7 @@ protected:
|
|||||||
if (std::chrono::system_clock::now() >= _midnight_tp)
|
if (std::chrono::system_clock::now() >= _midnight_tp)
|
||||||
{
|
{
|
||||||
_file_helper.close();
|
_file_helper.close();
|
||||||
_file_helper.open(_calc_filename(_base_filename, _extension));
|
_file_helper.open(calc_filename(_base_filename, _extension));
|
||||||
_midnight_tp = _calc_midnight_tp();
|
_midnight_tp = _calc_midnight_tp();
|
||||||
}
|
}
|
||||||
_file_helper.write(msg);
|
_file_helper.write(msg);
|
||||||
@ -150,17 +159,17 @@ private:
|
|||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
auto now = system_clock::now();
|
auto now = system_clock::now();
|
||||||
time_t tnow = std::chrono::system_clock::to_time_t(now);
|
time_t tnow = std::chrono::system_clock::to_time_t(now);
|
||||||
tm date = c11log::details::os::localtime(tnow);
|
tm date = spitlog::details::os::localtime(tnow);
|
||||||
date.tm_hour = date.tm_min = date.tm_sec = 0;
|
date.tm_hour = date.tm_min = date.tm_sec = 0;
|
||||||
auto midnight = std::chrono::system_clock::from_time_t(std::mktime(&date));
|
auto midnight = std::chrono::system_clock::from_time_t(std::mktime(&date));
|
||||||
return system_clock::time_point(midnight + hours(24));
|
return system_clock::time_point(midnight + hours(24));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create filename for the form basename.YYYY-MM-DD.extension
|
//Create filename for the form basename.YYYY-MM-DD.extension
|
||||||
static std::string _calc_filename(const std::string& basename, const std::string& extension)
|
static std::string calc_filename(const std::string& basename, const std::string& extension)
|
||||||
{
|
{
|
||||||
std::tm tm = c11log::details::os::localtime();
|
std::tm tm = spitlog::details::os::localtime();
|
||||||
std::ostringstream oss;
|
fast_oss oss;
|
||||||
oss << basename << '.';
|
oss << basename << '.';
|
||||||
oss << tm.tm_year + 1900 << '-' << std::setw(2) << std::setfill('0') << tm.tm_mon + 1 << '-' << tm.tm_mday;
|
oss << tm.tm_year + 1900 << '-' << std::setw(2) << std::setfill('0') << tm.tm_mon + 1 << '-' << tm.tm_mday;
|
||||||
oss << '.' << extension;
|
oss << '.' << extension;
|
@ -4,7 +4,7 @@
|
|||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
|
|
||||||
|
|
||||||
namespace c11log {
|
namespace spitlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
|
|
||||||
template <class Mutex>
|
template <class Mutex>
|
@ -7,7 +7,7 @@
|
|||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "./base_sink.h"
|
#include "./base_sink.h"
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "../details/log_msg.h"
|
#include "../details/log_msg.h"
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
@ -5,7 +5,7 @@
|
|||||||
#include "./ostream_sink.h"
|
#include "./ostream_sink.h"
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
|
|
||||||
namespace c11log
|
namespace spitlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user