Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
31971bf6
Commit
31971bf6
authored
Oct 31, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated example and added more creation functions
parent
c7b8c762
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
251 additions
and
144 deletions
+251
-144
ReadMe.txt
c11logtest/c11logtest/ReadMe.txt
+7
-7
c11logtest.vcxproj
c11logtest/c11logtest/c11logtest.vcxproj
+25
-23
c11logtest.vcxproj.filters
c11logtest/c11logtest/c11logtest.vcxproj.filters
+49
-43
stdafx.cpp
c11logtest/c11logtest/stdafx.cpp
+1
-1
bench.cpp
example/bench.cpp
+24
-18
example.cpp
example/example.cpp
+35
-17
common.h
include/spdlog/common.h
+2
-2
file_helper.h
include/spdlog/details/file_helper.h
+2
-2
logger_impl.h
include/spdlog/details/logger_impl.h
+9
-1
registry.h
include/spdlog/details/registry.h
+8
-3
spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+50
-0
logger.h
include/spdlog/logger.h
+2
-0
file_sinks.h
include/spdlog/sinks/file_sinks.h
+3
-3
spdlog.h
include/spdlog/spdlog.h
+34
-24
No files found.
c11logtest/c11logtest/ReadMe.txt
View file @
31971bf6
========================================================================
CONSOLE APPLICATION : sp
it
logtest Project Overview
CONSOLE APPLICATION : sp
d
logtest Project Overview
========================================================================
AppWizard has created this sp
it
logtest application for you.
AppWizard has created this sp
d
logtest application for you.
This file contains a summary of what you will find in each of the files that
make up your sp
it
logtest application.
make up your sp
d
logtest application.
sp
it
logtest.vcxproj
sp
d
logtest.vcxproj
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
information about the platforms, configurations, and project features selected with the
Application Wizard.
sp
it
logtest.vcxproj.filters
sp
d
logtest.vcxproj.filters
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
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
"Source Files" filter).
sp
it
logtest.cpp
sp
d
logtest.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
...
...
@@ -29,7 +29,7 @@ Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named sp
it
logtest.pch and a precompiled types file named StdAfx.obj.
named sp
d
logtest.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
...
...
c11logtest/c11logtest/c11logtest.vcxproj
View file @
31971bf6
...
...
@@ -13,7 +13,7 @@
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{DC7F2F3E-0D0E-4324-A278-410DBC4045AD}
</ProjectGuid>
<Keyword>
Win32Proj
</Keyword>
<RootNamespace>
sp
it
logtest
</RootNamespace>
<RootNamespace>
sp
d
logtest
</RootNamespace>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
...
...
@@ -85,28 +85,30 @@
<Text
Include=
"ReadMe.txt"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"..\..\include\spitlog\common.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\blocking_queue.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\fast_oss.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\fast_istostr.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\file_helper.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\line_logger.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\logger_impl.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\log_msg.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\null_mutex.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\os.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\pattern_formatter_impl.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\registry.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\details\stack_buf.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\formatter.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\logger.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\async_sink.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\base_sink.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\ostream_sink.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\file_sinks.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\null_sink.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\sink.h"
/>
<ClInclude
Include=
"..\..\include\spitlog\sinks\stdout_sinks.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\common.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\blocking_queue.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\fast_oss.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\fast_istostr.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\file_helper.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\line_logger.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\logger_impl.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\log_msg.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\null_mutex.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\os.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\pattern_formatter_impl.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\registry.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\spdlog_impl.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\details\stack_buf.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\formatter.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\logger.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\async_sink.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\base_sink.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\ostream_sink.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\file_sinks.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\null_sink.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\sink.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\sinks\stdout_sinks.h"
/>
<ClInclude
Include=
"..\..\include\spdlog\spdlog.h"
/>
<ClInclude
Include=
"stdafx.h"
/>
<ClInclude
Include=
"targetver.h"
/>
</ItemGroup>
...
...
c11logtest/c11logtest/c11logtest.vcxproj.filters
View file @
31971bf6
...
...
@@ -13,13 +13,13 @@
<UniqueIdentifier>
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
</UniqueIdentifier>
<Extensions>
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
</Extensions>
</Filter>
<Filter
Include=
"Header Files\
c11
log"
>
<Filter
Include=
"Header Files\
spd
log"
>
<UniqueIdentifier>
{bad4e9e3-82bd-4b02-9b4a-43198cc65844}
</UniqueIdentifier>
</Filter>
<Filter
Include=
"Header Files\
c11
log\details"
>
<Filter
Include=
"Header Files\
spd
log\details"
>
<UniqueIdentifier>
{a4cc3c0e-8713-4146-98c7-1e7ab4ed95f8}
</UniqueIdentifier>
</Filter>
<Filter
Include=
"Header Files\
c11
log\sinks"
>
<Filter
Include=
"Header Files\
spd
log\sinks"
>
<UniqueIdentifier>
{87170f3b-5292-49b8-8581-7db7cb9abd29}
</UniqueIdentifier>
</Filter>
</ItemGroup>
...
...
@@ -33,72 +33,78 @@
<ClInclude
Include=
"targetver.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
it
log\common.h"
>
<ClInclude
Include=
"..\..\include\sp
d
log\common.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\blocking_queue
.h"
>
<ClInclude
Include=
"..\..\include\sp
dlog\formatter
.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\fast_oss
.h"
>
<ClInclude
Include=
"..\..\include\sp
dlog\logger
.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\fast_istostr
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\async_sink
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\file_helper
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\base_sink
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\line_logger
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\null_sink
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\logger_impl
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\ostream_sink
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\log_msg
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\sink
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\null_mutex
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\stdout_sinks
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\os
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\blocking_queue
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\pattern_formatter_impl
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\fast_istostr
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\registry
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\fast_oss
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\details\stack_buf
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\file_helper
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\formatter
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\sinks\file_sinks
.h"
>
<Filter>
Header Files
\spdlog\sinks
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\
logger.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\line_
logger.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\sinks\async_sink
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\log_msg
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\sinks\base_sink
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\logger_impl
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\sinks\ostream_sink
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\os
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\sinks\file_sinks
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\null_mutex
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\sinks\null_sink
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\pattern_formatter_impl
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\sp
itlog\sinks\sink
.h"
>
<Filter>
Header Files
</Filter>
<ClInclude
Include=
"..\..\include\sp
dlog\details\registry
.h"
>
<Filter>
Header Files
\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\spitlog\sinks\stdout_sinks.h"
>
<ClInclude
Include=
"..\..\include\spdlog\details\stack_buf.h"
>
<Filter>
Header Files\spdlog\details
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\spdlog\spdlog.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"..\..\include\spdlog\details\spdlog_impl.h"
>
<Filter>
Header Files\spdlog\details
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"stdafx.cpp"
>
...
...
c11logtest/c11logtest/stdafx.cpp
View file @
31971bf6
// stdafx.cpp : source file that includes just the standard includes
// sp
it
logtest.pch will be the pre-compiled header
// sp
d
logtest.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
...
...
example/bench.cpp
View file @
31971bf6
// example.cpp : Simple logger example
//
#include "spitlog/logger.h"
#include "spitlog/sinks/async_sink.h"
#include "spitlog/sinks/file_sinks.h"
#include "spitlog/sinks/stdout_sinks.h"
#include "spitlog/sinks/null_sink.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/file_sinks.h"
#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/sinks/null_sink.h"
#include "utils.h"
#include "spitlog/details/registry.h"
using
namespace
std
;
using
namespace
std
::
chrono
;
using
namespace
sp
it
log
;
using
namespace
sp
d
log
;
using
namespace
utils
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
_
(
int
argc
,
char
*
argv
[])
{
try
{
using
namespace
spdlog
::
sinks
;
spdlog
::
create
<
daily_file_sink_st
>
(
"mylog"
,
"dailylog"
,
"txt"
);
const
unsigned
int
howmany
=
argc
<=
1
?
1500000
:
atoi
(
argv
[
1
]);
//spitlog::set_format("
%t");
auto
console
=
spitlog
::
create
<
sinks
::
stdout_sink_st
>
(
"reporter"
);
//console->set_format("[%n %l] %t");
console
->
set_level
(
spitlog
::
level
::
INFO
);
spdlog
::
set_pattern
(
"%Y-%m-%d %H:%M:%S.%e %l :
%t"
);
auto
console
=
spdlog
::
create
<
sinks
::
stdout_sink_st
>
(
"reporter"
);
console
->
info
(
"Starting bench with"
,
howmany
,
"iterations.."
);
console
->
log
()
<<
"Streams are also supprted: "
<<
std
::
hex
<<
255
;
spdlog
::
stop
();
auto
bench
=
spitlog
::
create
<
sinks
::
rotating_file_sink_st
>
(
"bench"
,
"myrotating"
,
"txt"
,
1024
*
1024
*
1
,
10
,
0
);
//return 0;
auto
bench
=
spdlog
::
create
<
sinks
::
rotating_file_sink_st
>
(
"bench"
,
"myrotating"
,
"txt"
,
1024
*
1024
*
1
,
10
,
0
);
//auto bench = sp
it
log::create<sinks::simple_file_sink_st>("bench", "simplelog.txt", 1);
//auto bench = sp
it
log::create<sinks::null_sink_st>("bench");
//auto bench = sp
d
log::create<sinks::simple_file_sink_st>("bench", "simplelog.txt", 1);
//auto bench = sp
d
log::create<sinks::null_sink_st>("bench");
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
++
i
)
{
...
...
@@ -37,9 +43,9 @@ int main(int argc, char* argv[])
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
co
nsole
->
info
(
"Total:"
)
<<
format
(
howmany
)
;
co
nsole
->
info
(
"Delta:"
)
<<
format
(
delta_d
)
;
co
nsole
->
info
(
"Rate:"
)
<<
format
(
howmany
/
delta_d
)
<<
"/sec
"
;
co
ut
<<
"Total:"
<<
format
(
howmany
)
<<
endl
;
co
ut
<<
"Delta:"
<<
format
(
delta_d
)
<<
endl
;
co
ut
<<
"Rate:"
<<
format
(
howmany
/
delta_d
)
<<
"/sec
\n
"
;
}
catch
(
std
::
exception
&
ex
)
...
...
example/example.cpp
View file @
31971bf6
// example.cpp : Simple logger example
//
#define FFLOG_ENABLE_TRACE
// example.cpp : spdlog usage example
//
#include <iostream>
#include "spitlog/logger.h"
#include "spitlog/sinks/stdout_sinks.h"
#include "spitlog/sinks/file_sinks.h"
using
namespace
std
;
using
namespace
spitlog
;
#include "spdlog/spdlog.h"
details
::
fast_oss
f
(
const
std
::
string
&
what
)
{
details
::
fast_oss
oss
;
oss
<<
what
;
return
oss
;
}
int
main_
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
auto
foss
=
f
(
"test2"
);
foss
.
str
();
namespace
spd
=
spdlog
;
try
{
std
::
string
filename
=
"spdlog_example"
;
auto
console
=
spd
::
stderr_logger_mt
(
"console"
);
console
->
info
(
"Welcome to spdlog!"
);
console
->
info
()
<<
"Creating file "
<<
filename
<<
".."
;
auto
file_logger
=
spd
::
rotating_logger_mt
(
"file_logger"
,
filename
,
1024
*
1024
*
5
,
3
);
file_logger
->
info
(
"Log file message number"
,
1
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
auto
square
=
i
*
i
;
file_logger
->
info
()
<<
i
<<
'*'
<<
i
<<
'='
<<
square
<<
" ("
<<
"0x"
<<
std
::
hex
<<
square
<<
")"
;
}
// Change log level to all loggers to warning and above
spd
::
set_level
(
spd
::
level
::
WARN
);
console
->
info
(
"This should not be displayed"
);
console
->
warn
(
"This should!"
);
// Change format pattern to all loggers
spd
::
set_pattern
(
" **** %Y-%m-%d %H:%M:%S.%e %l **** %t"
);
spd
::
get
(
"console"
)
->
warn
(
"This is another message with different format"
);
}
catch
(
const
spd
::
spdlog_ex
&
ex
)
{
std
::
cout
<<
"Log failed: "
<<
ex
.
what
()
<<
std
::
endl
;
}
return
0
;
}
include/spdlog/common.h
View file @
31971bf6
...
...
@@ -41,10 +41,10 @@ inline const char* to_str(spdlog::level::level_enum l)
//
// Log exception
//
class
fflog_exception
:
public
std
::
exception
class
spdlog_ex
:
public
std
::
exception
{
public
:
fflog_exception
(
const
std
::
string
&
msg
)
:
_msg
(
msg
)
{};
spdlog_ex
(
const
std
::
string
&
msg
)
:
_msg
(
msg
)
{};
const
char
*
what
()
const
throw
()
override
{
return
_msg
.
c_str
();
}
...
...
include/spdlog/details/file_helper.h
View file @
31971bf6
...
...
@@ -54,7 +54,7 @@ public:
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
sleep_ms_bewteen_tries
));
}
throw
fflog_exception
(
"Failed opening file "
+
filename
+
" for writing"
);
throw
spdlog_ex
(
"Failed opening file "
+
filename
+
" for writing"
);
}
void
close
()
...
...
@@ -71,7 +71,7 @@ public:
auto
&
buf
=
msg
.
formatted
.
buf
();
size_t
size
=
buf
.
size
();
if
(
std
::
fwrite
(
buf
.
data
(),
sizeof
(
char
),
size
,
_fd
)
!=
size
)
throw
fflog_exception
(
"Failed writing to file "
+
_filename
);
throw
spdlog_ex
(
"Failed writing to file "
+
_filename
);
if
(
--
_flush_countdown
==
0
)
{
...
...
include/spdlog/details/logger_impl.h
View file @
31971bf6
...
...
@@ -116,8 +116,16 @@ inline void spdlog::logger::stop_logging()
inline
void
spdlog
::
logger
::
_variadic_log
(
spdlog
::
details
::
line_logger
&
)
{}
template
<
typename
Last
>
inline
void
spdlog
::
logger
::
_variadic_log
(
spdlog
::
details
::
line_logger
&
l
,
const
Last
&
last
)
{
l
.
write
(
last
);
}
template
<
typename
First
,
typename
...
Rest
>
void
spdlog
::
logger
::
_variadic_log
(
spdlog
::
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
)
inline
void
spdlog
::
logger
::
_variadic_log
(
spdlog
::
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
)
{
l
.
write
(
first
);
l
.
write
(
' '
);
...
...
include/spdlog/details/registry.h
View file @
31971bf6
#pragma once
// Loggers registy of unique name->logger pointer
//
If 2 loggers with same name are added, the second will be overrun the first
//
An attempt to create a logger with an alreasy existing name will be ignored
// If user requests a non existing logger, nullptr will be returned
// This class is thread safe
...
...
@@ -16,10 +16,10 @@ namespace details {
class
registry
{
public
:
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
name
)
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
logger_
name
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
auto
found
=
_loggers
.
find
(
name
);
auto
found
=
_loggers
.
find
(
logger_
name
);
return
found
==
_loggers
.
end
()
?
nullptr
:
found
->
second
;
}
...
...
@@ -27,6 +27,11 @@ public:
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
//If already exists, just return it
auto
found
=
_loggers
.
find
(
logger_name
);
if
(
found
!=
_loggers
.
end
())
return
found
->
second
;
auto
new_logger
=
std
::
make_shared
<
logger
>
(
logger_name
,
sinks_begin
,
sinks_end
);
new_logger
->
set_formatter
(
_formatter
);
new_logger
->
set_level
(
_level
);
...
...
include/spdlog/details/spdlog_impl.h
View file @
31971bf6
...
...
@@ -4,12 +4,62 @@
// Global registry functions
//
#include "registry.h"
#include "../sinks/file_sinks.h"
#include "../sinks/stdout_sinks.h"
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
get
(
const
std
::
string
&
name
)
{
return
details
::
registry
::
instance
().
get
(
name
);
}
// Create multi/single threaded rotating file logger
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
)
{
return
create
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
flush_inverval
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
)
{
return
create
<
spdlog
::
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
flush_inverval
);
}
// Create file logger which creates new file at midnight):
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
)
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
flush_inverval
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
)
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
flush_inverval
);
}
// Create stdout/stderr loggers
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
create
<
spdlog
::
sinks
::
stdout_sink_mt
>
(
logger_name
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_logger_st
(
const
std
::
string
&
logger_name
)
{
return
create
<
spdlog
::
sinks
::
stdout_sink_st
>
(
logger_name
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
create
<
spdlog
::
sinks
::
stderr_sink_mt
>
(
logger_name
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_logger_st
(
const
std
::
string
&
logger_name
)
{
return
create
<
spdlog
::
sinks
::
stderr_sink_st
>
(
logger_name
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create
(
const
std
::
string
&
logger_name
,
spdlog
::
sinks_init_list
sinks
)
{
return
details
::
registry
::
instance
().
create
(
logger_name
,
sinks
);
...
...
include/spdlog/logger.h
View file @
31971bf6
...
...
@@ -64,6 +64,8 @@ private:
std
::
vector
<
sink_ptr
>
_sinks
;
std
::
atomic_int
_level
;
void
_variadic_log
(
details
::
line_logger
&
l
);
template
<
typename
Last
>
inline
void
_variadic_log
(
spdlog
::
details
::
line_logger
&
l
,
const
Last
&
last
);
template
<
typename
First
,
typename
...
Rest
>
void
_variadic_log
(
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
);
void
_log_msg
(
details
::
log_msg
&
msg
);
...
...
include/spdlog/sinks/file_sinks.h
View file @
31971bf6
...
...
@@ -48,8 +48,8 @@ class rotating_file_sink : public base_sink<Mutex>
{
public
:
rotating_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
const
std
::
size_t
max_size
,
const
std
::
size_t
max_files
,
const
std
::
size_t
flush_inverval
=
0
)
:
std
::
size_t
max_size
,
std
::
size_t
max_files
,
std
::
size_t
flush_inverval
=
0
)
:
_base_filename
(
base_filename
),
_extension
(
extension
),
_max_size
(
max_size
),
...
...
@@ -104,7 +104,7 @@ private:
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
);
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
src
+
" to "
+
target
);
}
}
auto
cur_name
=
_file_helper
.
filename
();
...
...
include/spdlog/spdlog.h
View file @
31971bf6
...
...
@@ -29,47 +29,57 @@ namespace spdlog
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
name
);
// Example:
// auto logger = spdlog::create("mylog", {sink1, sink2});
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
);
// Set global formatting
// spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %t");
void
set_pattern
(
const
std
::
string
&
format_string
);
//Set global logging level
void
set_level
(
level
::
level_enum
log_level
);
// Create multi/single threaded rotating file logger
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
=
0
);
std
::
shared_ptr
<
logger
>
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
=
0
);
// Create file logger which creates new file at midnight):
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
=
0
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
=
0
);
// Create stdout/stderr loggers
std
::
shared_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stdout_logger_st
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stderr_logger_mt
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stderr_logger_st
(
const
std
::
string
&
logger_name
);
// Example (create a logger with daily rotating file):
// using namespace spdlog::sinks;
// spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
template
<
typename
Sink
,
typename
...
Args
>
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...
args
);
// Example:
// using namespace spdlog::sinks;
// std::vector<spdlog::sink_ptr> mySinks;
// mySinks.push_back(std::make_shared<rotating_file_sink_mt>("filename", "txt", 1024 * 1024 * 5, 10));
// mySinks.push_back(std::make_shared<stdout_sink_mt>());
// spdlog::create("mylog", mySinks.begin(), mySinks.end());
//
// Create a logger with multiple sinks
//
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
);
template
<
class
It
>
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
);
// Set global formatting
// Example:
// spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %t");
void
set_pattern
(
const
std
::
string
&
format_string
);
// Create a logger with templated sink type
// Example: spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
template
<
typename
Sink
,
typename
...
Args
>
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...
args
);
// Set global formatter object
void
set_formatter
(
formatter_ptr
f
);
//Set global active logging level
void
set_level
(
level
::
level_enum
log_level
);
//Stop all loggers
void
stop
();
//
// Trace macro
to turn on/off at compile tim
e
// Trace macro
enabled only at debug compil
e
// Example: SPDLOG_TRACE(my_logger, "Some trace message");
//
#ifdef _DEBUG
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment