Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
c8610d9a
Commit
c8610d9a
authored
Apr 06, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for color formatting
parent
93d41b2c
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
105 additions
and
73 deletions
+105
-73
bench/boost-bench-mt.cpp
bench/boost-bench-mt.cpp
+0
-1
bench/easylogging-bench-async.cpp
bench/easylogging-bench-async.cpp
+1
-1
bench/easylogging-bench-mt.cpp
bench/easylogging-bench-mt.cpp
+1
-1
bench/easylogging-bench.cpp
bench/easylogging-bench.cpp
+2
-2
bench/g3log-async.cpp
bench/g3log-async.cpp
+3
-2
bench/glog-bench.cpp
bench/glog-bench.cpp
+0
-1
bench/log4cplus-bench-mt.cpp
bench/log4cplus-bench-mt.cpp
+6
-8
bench/log4cplus-bench.cpp
bench/log4cplus-bench.cpp
+5
-7
bench/log4cpp-bench-mt.cpp
bench/log4cpp-bench-mt.cpp
+6
-6
bench/log4cpp-bench.cpp
bench/log4cpp-bench.cpp
+5
-5
bench/p7-bench-mt.cpp
bench/p7-bench-mt.cpp
+10
-13
bench/p7-bench.cpp
bench/p7-bench.cpp
+7
-11
bench/spdlog-async.cpp
bench/spdlog-async.cpp
+3
-3
bench/spdlog-bench-mt.cpp
bench/spdlog-bench-mt.cpp
+1
-1
include/spdlog/details/log_msg.h
include/spdlog/details/log_msg.h
+3
-0
include/spdlog/details/os.h
include/spdlog/details/os.h
+1
-1
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+30
-1
include/spdlog/sinks/ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+21
-9
No files found.
bench/boost-bench-mt.cpp
View file @
c8610d9a
...
@@ -82,6 +82,5 @@ int main(int argc, char *argv[])
...
@@ -82,6 +82,5 @@ int main(int argc, char *argv[])
std
::
cout
<<
"Delta = "
<<
deltaf
<<
" seconds"
<<
std
::
endl
;
std
::
cout
<<
"Delta = "
<<
deltaf
<<
" seconds"
<<
std
::
endl
;
std
::
cout
<<
"Rate = "
<<
rate
<<
"/sec"
<<
std
::
endl
;
std
::
cout
<<
"Rate = "
<<
rate
<<
"/sec"
<<
std
::
endl
;
return
0
;
return
0
;
}
}
bench/easylogging-bench-async.cpp
View file @
c8610d9a
...
@@ -11,8 +11,8 @@
...
@@ -11,8 +11,8 @@
#define ELPP_THREAD_SAFE
#define ELPP_THREAD_SAFE
#define ELPP_EXPERIMENTAL_ASYNC
#define ELPP_EXPERIMENTAL_ASYNC
#include "easylogging++.h"
#include "easylogging++.cc"
#include "easylogging++.cc"
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP
using
namespace
std
;
using
namespace
std
;
...
...
bench/easylogging-bench-mt.cpp
View file @
c8610d9a
...
@@ -10,8 +10,8 @@
...
@@ -10,8 +10,8 @@
#include <vector>
#include <vector>
#define ELPP_THREAD_SAFE
#define ELPP_THREAD_SAFE
#include "easylogging++.h"
#include "easylogging++.cc"
#include "easylogging++.cc"
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP
using
namespace
std
;
using
namespace
std
;
...
...
bench/easylogging-bench.cpp
View file @
c8610d9a
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
#include <chrono>
#include <chrono>
#include <iostream>
#include <iostream>
#include "easylogging++.h"
#include "easylogging++.cc"
#include "easylogging++.cc"
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
INITIALIZE_EASYLOGGINGPP
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
...
@@ -21,7 +21,7 @@ int main(int, char *[])
...
@@ -21,7 +21,7 @@ int main(int, char *[])
el
::
Configurations
conf
(
"easyl.conf"
);
el
::
Configurations
conf
(
"easyl.conf"
);
el
::
Loggers
::
reconfigureLogger
(
"default"
,
conf
);
el
::
Loggers
::
reconfigureLogger
(
"default"
,
conf
);
el
::
Logger
*
defaultLogger
=
el
::
Loggers
::
getLogger
(
"default"
);
el
::
Logger
*
defaultLogger
=
el
::
Loggers
::
getLogger
(
"default"
);
auto
start
=
clock
::
now
();
auto
start
=
clock
::
now
();
for
(
int
i
=
0
;
i
<
howmany
;
++
i
)
for
(
int
i
=
0
;
i
<
howmany
;
++
i
)
...
...
bench/g3log-async.cpp
View file @
c8610d9a
...
@@ -13,7 +13,8 @@
...
@@ -13,7 +13,8 @@
#include "g3log/logworker.hpp"
#include "g3log/logworker.hpp"
using
namespace
std
;
using
namespace
std
;
template
<
typename
T
>
std
::
string
format
(
const
T
&
value
);
template
<
typename
T
>
std
::
string
format
(
const
T
&
value
);
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -27,7 +28,7 @@ int main(int argc, char *argv[])
...
@@ -27,7 +28,7 @@ int main(int argc, char *argv[])
int
howmany
=
1000000
;
int
howmany
=
1000000
;
auto
worker
=
g3
::
LogWorker
::
createLogWorker
();
auto
worker
=
g3
::
LogWorker
::
createLogWorker
();
auto
handle
=
worker
->
addDefaultLogger
(
argv
[
0
],
"logs"
);
auto
handle
=
worker
->
addDefaultLogger
(
argv
[
0
],
"logs"
);
g3
::
initializeLogging
(
worker
.
get
());
g3
::
initializeLogging
(
worker
.
get
());
std
::
atomic
<
int
>
msg_counter
{
0
};
std
::
atomic
<
int
>
msg_counter
{
0
};
...
...
bench/glog-bench.cpp
View file @
c8610d9a
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
#include "glog/logging.h"
#include "glog/logging.h"
int
main
(
int
,
char
*
argv
[])
int
main
(
int
,
char
*
argv
[])
{
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
...
...
bench/log4cplus-bench-mt.cpp
View file @
c8610d9a
...
@@ -10,17 +10,17 @@
...
@@ -10,17 +10,17 @@
#include <thread>
#include <thread>
#include <vector>
#include <vector>
#include "log4cplus/logger.h"
#include "log4cplus/fileappender.h"
#include "log4cplus/fileappender.h"
#include "log4cplus/layout.h"
#include "log4cplus/ndc.h"
#include "log4cplus/helpers/loglog.h"
#include "log4cplus/helpers/loglog.h"
#include "log4cplus/helpers/property.h"
#include "log4cplus/helpers/property.h"
#include "log4cplus/layout.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/ndc.h"
using
namespace
log4cplus
;
using
namespace
log4cplus
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
using
clock
=
steady_clock
;
using
clock
=
steady_clock
;
...
@@ -32,13 +32,11 @@ int main(int argc, char * argv[])
...
@@ -32,13 +32,11 @@ int main(int argc, char * argv[])
int
howmany
=
1000000
;
int
howmany
=
1000000
;
log4cplus
::
initialize
();
log4cplus
::
initialize
();
SharedFileAppenderPtr
append
(
SharedFileAppenderPtr
append
(
new
FileAppender
(
LOG4CPLUS_TEXT
(
"logs/log4cplus-bench-mt.log"
),
std
::
ios_base
::
trunc
,
true
,
true
));
new
FileAppender
(
LOG4CPLUS_TEXT
(
"logs/log4cplus-bench-mt.log"
),
std
::
ios_base
::
trunc
,
true
,
true
));
append
->
setName
(
LOG4CPLUS_TEXT
(
"File"
));
append
->
setName
(
LOG4CPLUS_TEXT
(
"File"
));
log4cplus
::
tstring
pattern
=
LOG4CPLUS_TEXT
(
"%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n"
);
log4cplus
::
tstring
pattern
=
LOG4CPLUS_TEXT
(
"%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n"
);
append
->
setLayout
(
std
::
auto_ptr
<
Layout
>
(
new
PatternLayout
(
pattern
))
);
append
->
setLayout
(
std
::
auto_ptr
<
Layout
>
(
new
PatternLayout
(
pattern
))
);
append
->
getloc
();
append
->
getloc
();
Logger
::
getRoot
().
addAppender
(
SharedAppenderPtr
(
append
.
get
()));
Logger
::
getRoot
().
addAppender
(
SharedAppenderPtr
(
append
.
get
()));
...
...
bench/log4cplus-bench.cpp
View file @
c8610d9a
...
@@ -7,13 +7,13 @@
...
@@ -7,13 +7,13 @@
#include <iostream>
#include <iostream>
#include <memory>
#include <memory>
#include "log4cplus/logger.h"
#include "log4cplus/fileappender.h"
#include "log4cplus/fileappender.h"
#include "log4cplus/layout.h"
#include "log4cplus/ndc.h"
#include "log4cplus/helpers/loglog.h"
#include "log4cplus/helpers/loglog.h"
#include "log4cplus/helpers/property.h"
#include "log4cplus/helpers/property.h"
#include "log4cplus/layout.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/ndc.h"
using
namespace
log4cplus
;
using
namespace
log4cplus
;
...
@@ -25,13 +25,11 @@ int main(int, char *[])
...
@@ -25,13 +25,11 @@ int main(int, char *[])
int
howmany
=
1000000
;
int
howmany
=
1000000
;
log4cplus
::
initialize
();
log4cplus
::
initialize
();
SharedFileAppenderPtr
append
(
SharedFileAppenderPtr
append
(
new
FileAppender
(
LOG4CPLUS_TEXT
(
"logs/log4cplus-bench.log"
),
std
::
ios_base
::
trunc
,
true
,
true
));
new
FileAppender
(
LOG4CPLUS_TEXT
(
"logs/log4cplus-bench.log"
),
std
::
ios_base
::
trunc
,
true
,
true
));
append
->
setName
(
LOG4CPLUS_TEXT
(
"File"
));
append
->
setName
(
LOG4CPLUS_TEXT
(
"File"
));
log4cplus
::
tstring
pattern
=
LOG4CPLUS_TEXT
(
"%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n"
);
log4cplus
::
tstring
pattern
=
LOG4CPLUS_TEXT
(
"%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n"
);
append
->
setLayout
(
std
::
auto_ptr
<
Layout
>
(
new
PatternLayout
(
pattern
))
);
append
->
setLayout
(
std
::
auto_ptr
<
Layout
>
(
new
PatternLayout
(
pattern
))
);
append
->
getloc
();
append
->
getloc
();
Logger
::
getRoot
().
addAppender
(
SharedAppenderPtr
(
append
.
get
()));
Logger
::
getRoot
().
addAppender
(
SharedAppenderPtr
(
append
.
get
()));
...
...
bench/log4cpp-bench-mt.cpp
View file @
c8610d9a
...
@@ -10,15 +10,15 @@
...
@@ -10,15 +10,15 @@
#include <thread>
#include <thread>
#include <vector>
#include <vector>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Category.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Priority.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/Priority.hh"
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
using
clock
=
steady_clock
;
using
clock
=
steady_clock
;
...
@@ -34,7 +34,7 @@ int main(int argc, char * argv[])
...
@@ -34,7 +34,7 @@ int main(int argc, char * argv[])
layout
->
setConversionPattern
(
"%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n"
);
layout
->
setConversionPattern
(
"%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n"
);
appender
->
setLayout
(
layout
);
appender
->
setLayout
(
layout
);
log4cpp
::
Category
&
root
=
log4cpp
::
Category
::
getRoot
();
log4cpp
::
Category
&
root
=
log4cpp
::
Category
::
getRoot
();
root
.
addAppender
(
appender
);
root
.
addAppender
(
appender
);
root
.
setPriority
(
log4cpp
::
Priority
::
INFO
);
root
.
setPriority
(
log4cpp
::
Priority
::
INFO
);
...
...
bench/log4cpp-bench.cpp
View file @
c8610d9a
...
@@ -7,13 +7,13 @@
...
@@ -7,13 +7,13 @@
#include <iostream>
#include <iostream>
#include <memory>
#include <memory>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Category.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Priority.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/Priority.hh"
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
{
...
@@ -27,7 +27,7 @@ int main(int, char *[])
...
@@ -27,7 +27,7 @@ int main(int, char *[])
layout
->
setConversionPattern
(
"%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n"
);
layout
->
setConversionPattern
(
"%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n"
);
appender
->
setLayout
(
layout
);
appender
->
setLayout
(
layout
);
log4cpp
::
Category
&
root
=
log4cpp
::
Category
::
getRoot
();
log4cpp
::
Category
&
root
=
log4cpp
::
Category
::
getRoot
();
root
.
addAppender
(
appender
);
root
.
addAppender
(
appender
);
root
.
setPriority
(
log4cpp
::
Priority
::
INFO
);
root
.
setPriority
(
log4cpp
::
Priority
::
INFO
);
...
...
bench/p7-bench-mt.cpp
View file @
c8610d9a
...
@@ -5,15 +5,14 @@
...
@@ -5,15 +5,14 @@
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <functional>
#include <iostream>
#include <iostream>
#include <memory>
#include <thread>
#include <thread>
#include <vector>
#include <vector>
#include <memory>
#include <functional>
#include "P7_Trace.h"
#include "P7_Trace.h"
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
...
@@ -27,10 +26,9 @@ int main(int argc, char *argv[])
...
@@ -27,10 +26,9 @@ int main(int argc, char *argv[])
IP7_Trace
::
hModule
module
=
NULL
;
IP7_Trace
::
hModule
module
=
NULL
;
//create P7 client object
// create P7 client object
std
::
unique_ptr
<
IP7_Client
,
std
::
function
<
void
(
IP7_Client
*
)
>>
client
(
std
::
unique_ptr
<
IP7_Client
,
std
::
function
<
void
(
IP7_Client
*
)
>>
client
(
P7_Create_Client
(
TM
(
"/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench-mt"
)),
P7_Create_Client
(
TM
(
"/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench-mt"
)),
[
&
](
IP7_Client
*
ptr
)
{
[
&
](
IP7_Client
*
ptr
){
if
(
ptr
)
if
(
ptr
)
ptr
->
Release
();
ptr
->
Release
();
});
});
...
@@ -41,10 +39,9 @@ int main(int argc, char *argv[])
...
@@ -41,10 +39,9 @@ int main(int argc, char *argv[])
return
1
;
return
1
;
}
}
//create P7 trace object 1
// create P7 trace object 1
std
::
unique_ptr
<
IP7_Trace
,
std
::
function
<
void
(
IP7_Trace
*
)
>>
trace
(
std
::
unique_ptr
<
IP7_Trace
,
std
::
function
<
void
(
IP7_Trace
*
)
>>
trace
(
P7_Create_Trace
(
client
.
get
(),
TM
(
"Trace channel 1"
)),
P7_Create_Trace
(
client
.
get
(),
TM
(
"Trace channel 1"
)),
[
&
](
IP7_Trace
*
ptr
)
{
[
&
](
IP7_Trace
*
ptr
){
if
(
ptr
)
if
(
ptr
)
ptr
->
Release
();
ptr
->
Release
();
});
});
...
@@ -65,7 +62,7 @@ int main(int argc, char *argv[])
...
@@ -65,7 +62,7 @@ int main(int argc, char *argv[])
for
(
int
t
=
0
;
t
<
thread_count
;
++
t
)
for
(
int
t
=
0
;
t
<
thread_count
;
++
t
)
{
{
threads
.
push_back
(
std
::
thread
([
&
]()
{
threads
.
push_back
(
std
::
thread
([
&
]()
{
trace
->
Register_Thread
(
TM
(
"Application"
),
t
+
1
);
trace
->
Register_Thread
(
TM
(
"Application"
),
t
+
1
);
while
(
true
)
while
(
true
)
{
{
int
counter
=
++
msg_counter
;
int
counter
=
++
msg_counter
;
...
@@ -73,7 +70,7 @@ int main(int argc, char *argv[])
...
@@ -73,7 +70,7 @@ int main(int argc, char *argv[])
break
;
break
;
trace
->
P7_INFO
(
module
,
TM
(
"p7 message #%d: This is some text for your pleasure"
),
counter
);
trace
->
P7_INFO
(
module
,
TM
(
"p7 message #%d: This is some text for your pleasure"
),
counter
);
}
}
trace
->
Register_Thread
(
TM
(
"Application"
),
t
+
1
);
trace
->
Register_Thread
(
TM
(
"Application"
),
t
+
1
);
}));
}));
}
}
...
...
bench/p7-bench.cpp
View file @
c8610d9a
...
@@ -4,13 +4,12 @@
...
@@ -4,13 +4,12 @@
//
//
#include <chrono>
#include <chrono>
#include <functional>
#include <iostream>
#include <iostream>
#include <memory>
#include <memory>
#include <functional>
#include "P7_Trace.h"
#include "P7_Trace.h"
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
{
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
...
@@ -20,10 +19,9 @@ int main(int, char *[])
...
@@ -20,10 +19,9 @@ int main(int, char *[])
IP7_Trace
::
hModule
module
=
NULL
;
IP7_Trace
::
hModule
module
=
NULL
;
//create P7 client object
// create P7 client object
std
::
unique_ptr
<
IP7_Client
,
std
::
function
<
void
(
IP7_Client
*
)
>>
client
(
std
::
unique_ptr
<
IP7_Client
,
std
::
function
<
void
(
IP7_Client
*
)
>>
client
(
P7_Create_Client
(
TM
(
"/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench"
)),
P7_Create_Client
(
TM
(
"/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench"
)),
[
&
](
IP7_Client
*
ptr
)
{
[
&
](
IP7_Client
*
ptr
){
if
(
ptr
)
if
(
ptr
)
ptr
->
Release
();
ptr
->
Release
();
});
});
...
@@ -34,10 +32,9 @@ int main(int, char *[])
...
@@ -34,10 +32,9 @@ int main(int, char *[])
return
1
;
return
1
;
}
}
//create P7 trace object 1
// create P7 trace object 1
std
::
unique_ptr
<
IP7_Trace
,
std
::
function
<
void
(
IP7_Trace
*
)
>>
trace
(
std
::
unique_ptr
<
IP7_Trace
,
std
::
function
<
void
(
IP7_Trace
*
)
>>
trace
(
P7_Create_Trace
(
client
.
get
(),
TM
(
"Trace channel 1"
)),
P7_Create_Trace
(
client
.
get
(),
TM
(
"Trace channel 1"
)),
[
&
](
IP7_Trace
*
ptr
)
{
[
&
](
IP7_Trace
*
ptr
){
if
(
ptr
)
if
(
ptr
)
ptr
->
Release
();
ptr
->
Release
();
});
});
...
@@ -55,7 +52,6 @@ int main(int, char *[])
...
@@ -55,7 +52,6 @@ int main(int, char *[])
for
(
int
i
=
0
;
i
<
howmany
;
++
i
)
for
(
int
i
=
0
;
i
<
howmany
;
++
i
)
trace
->
P7_INFO
(
module
,
TM
(
"p7 message #%d: This is some text for your pleasure"
),
i
);
trace
->
P7_INFO
(
module
,
TM
(
"p7 message #%d: This is some text for your pleasure"
),
i
);
duration
<
float
>
delta
=
clock
::
now
()
-
start
;
duration
<
float
>
delta
=
clock
::
now
()
-
start
;
float
deltaf
=
delta
.
count
();
float
deltaf
=
delta
.
count
();
auto
rate
=
howmany
/
deltaf
;
auto
rate
=
howmany
/
deltaf
;
...
...
bench/spdlog-async.cpp
View file @
c8610d9a
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <iostream>
#include <cstdlib>
#include <cstdlib>
#include <iostream>
#include <thread>
#include <thread>
#include <vector>
#include <vector>
...
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
...
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
run
=
false
;
run
=
false
;
}));
}));
while
(
run
)
while
(
run
)
{
{
std
::
atomic
<
int
>
msg_counter
{
0
};
std
::
atomic
<
int
>
msg_counter
{
0
};
std
::
vector
<
std
::
thread
>
threads
;
std
::
vector
<
std
::
thread
>
threads
;
...
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
...
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
std
::
cout
<<
"Threads: "
<<
thread_count
<<
std
::
endl
;
std
::
cout
<<
"Threads: "
<<
thread_count
<<
std
::
endl
;
std
::
cout
<<
"Delta = "
<<
std
::
fixed
<<
deltaf
<<
" seconds"
<<
std
::
endl
;
std
::
cout
<<
"Delta = "
<<
std
::
fixed
<<
deltaf
<<
" seconds"
<<
std
::
endl
;
std
::
cout
<<
"Rate = "
<<
std
::
fixed
<<
rate
<<
"/sec"
<<
std
::
endl
;
std
::
cout
<<
"Rate = "
<<
std
::
fixed
<<
rate
<<
"/sec"
<<
std
::
endl
;
}
//while
}
//
while
stoper
.
join
();
stoper
.
join
();
...
...
bench/spdlog-bench-mt.cpp
View file @
c8610d9a
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <iostream>
#include <cstdlib>
#include <cstdlib>
#include <iostream>
#include <thread>
#include <thread>
#include <vector>
#include <vector>
...
...
include/spdlog/details/log_msg.h
View file @
c8610d9a
...
@@ -40,6 +40,9 @@ struct log_msg
...
@@ -40,6 +40,9 @@ struct log_msg
fmt
::
MemoryWriter
raw
;
fmt
::
MemoryWriter
raw
;
fmt
::
MemoryWriter
formatted
;
fmt
::
MemoryWriter
formatted
;
size_t
msg_id
{
0
};
size_t
msg_id
{
0
};
// wrap this range with color codes
size_t
color_range_start
{
0
};
size_t
color_range_end
{
0
};
};
};
}
// namespace details
}
// namespace details
}
// namespace spdlog
}
// namespace spdlog
include/spdlog/details/os.h
View file @
c8610d9a
include/spdlog/details/pattern_formatter_impl.h
View file @
c8610d9a
...
@@ -421,7 +421,24 @@ private:
...
@@ -421,7 +421,24 @@ private:
std
::
string
_str
;
std
::
string
_str
;
};
};
// set the color range. expect it to be in the form of "%^colored text%$"
class
start_color_formatter
SPDLOG_FINAL
:
public
flag_formatter
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
)
override
{
msg
.
color_range_start
=
msg
.
formatted
.
size
();
}
};
class
stop_color_formatter
SPDLOG_FINAL
:
public
flag_formatter
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
)
override
{
msg
.
color_range_end
=
msg
.
formatted
.
size
();
}
};
// Full info formatter
// Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
class
full_formatter
SPDLOG_FINAL
:
public
flag_formatter
class
full_formatter
SPDLOG_FINAL
:
public
flag_formatter
{
{
...
@@ -462,8 +479,13 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
...
@@ -462,8 +479,13 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
msg
.
formatted
<<
'['
<<
*
msg
.
logger_name
<<
"] "
;
msg
.
formatted
<<
'['
<<
*
msg
.
logger_name
<<
"] "
;
#endif
#endif
msg
.
formatted
<<
'['
<<
level
::
to_str
(
msg
.
level
)
<<
"] "
;
const
char
*
level_name
=
level
::
to_str
(
msg
.
level
);
size_t
level_name_size
=
strlen
(
level_name
);
msg
.
formatted
<<
'['
<<
fmt
::
StringRef
(
level_name
,
level_name_size
)
<<
"] "
;
msg
.
formatted
<<
fmt
::
StringRef
(
msg
.
raw
.
data
(),
msg
.
raw
.
size
());
msg
.
formatted
<<
fmt
::
StringRef
(
msg
.
raw
.
data
(),
msg
.
raw
.
size
());
// wrap the level with color
msg
.
color_range_start
=
37
;
msg
.
color_range_end
=
37
+
level_name_size
;
}
}
};
};
...
@@ -491,6 +513,7 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string &patter
...
@@ -491,6 +513,7 @@ inline void spdlog::pattern_formatter::compile_pattern(const std::string &patter
{
{
_formatters
.
push_back
(
std
::
move
(
user_chars
));
_formatters
.
push_back
(
std
::
move
(
user_chars
));
}
}
// if(
if
(
++
it
!=
end
)
if
(
++
it
!=
end
)
{
{
handle_flag
(
*
it
);
handle_flag
(
*
it
);
...
@@ -644,6 +667,12 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
...
@@ -644,6 +667,12 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
case
(
'i'
):
case
(
'i'
):
_formatters
.
emplace_back
(
new
details
::
i_formatter
());
_formatters
.
emplace_back
(
new
details
::
i_formatter
());
break
;
break
;
case
(
'^'
):
_formatters
.
emplace_back
(
new
details
::
start_color_formatter
());
break
;
case
(
'$'
):
_formatters
.
emplace_back
(
new
details
::
stop_color_formatter
());
break
;
default:
// Unknown flag appears as is
default:
// Unknown flag appears as is
_formatters
.
emplace_back
(
new
details
::
ch_formatter
(
'%'
));
_formatters
.
emplace_back
(
new
details
::
ch_formatter
(
'%'
));
...
...
include/spdlog/sinks/ansicolor_sink.h
View file @
c8610d9a
...
@@ -28,9 +28,9 @@ public:
...
@@ -28,9 +28,9 @@ public:
:
target_file_
(
file
)
:
target_file_
(
file
)
{
{
should_do_colors_
=
details
::
os
::
in_terminal
(
file
)
&&
details
::
os
::
is_color_terminal
();
should_do_colors_
=
details
::
os
::
in_terminal
(
file
)
&&
details
::
os
::
is_color_terminal
();
colors_
[
level
::
trace
]
=
cyan
;
colors_
[
level
::
trace
]
=
magenta
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
reset
;
colors_
[
level
::
info
]
=
green
;
colors_
[
level
::
warn
]
=
yellow
+
bold
;
colors_
[
level
::
warn
]
=
yellow
+
bold
;
colors_
[
level
::
err
]
=
red
+
bold
;
colors_
[
level
::
err
]
=
red
+
bold
;
colors_
[
level
::
critical
]
=
bold
+
on_red
;
colors_
[
level
::
critical
]
=
bold
+
on_red
;
...
@@ -83,17 +83,20 @@ protected:
...
@@ -83,17 +83,20 @@ protected:
{
{
// Wrap the originally formatted message in color codes.
// Wrap the originally formatted message in color codes.
// If color is not supported in the terminal, log as is instead.
// If color is not supported in the terminal, log as is instead.
if
(
should_do_colors_
)
if
(
should_do_colors_
&&
msg
.
color_range_end
>
msg
.
color_range_start
)
{
{
const
std
::
string
&
prefix
=
colors_
[
msg
.
level
];
// before color range
fwrite
(
prefix
.
data
(),
sizeof
(
char
),
prefix
.
size
(),
target_file_
);
_print_range
(
msg
,
0
,
msg
.
color_range_start
);
fwrite
(
msg
.
formatted
.
data
(),
sizeof
(
char
),
msg
.
formatted
.
size
(),
target_file_
);
// in color range
fwrite
(
reset
.
data
(),
sizeof
(
char
),
reset
.
size
(),
target_file_
);
_print_ccode
(
colors_
[
msg
.
level
]);
fwrite
(
clear_line
.
data
(),
sizeof
(
char
),
clear_line
.
size
(),
target_file_
);
_print_range
(
msg
,
msg
.
color_range_start
,
msg
.
color_range_end
);
_print_ccode
(
reset
);
// after color range
_print_range
(
msg
,
msg
.
color_range_end
,
msg
.
formatted
.
size
());
}
}
else
else
{
{
fwrite
(
msg
.
formatted
.
data
(),
sizeof
(
char
),
msg
.
formatted
.
size
(),
target_file_
);
_print_range
(
msg
,
0
,
msg
.
formatted
.
size
()
);
}
}
_flush
();
_flush
();
}
}
...
@@ -103,6 +106,15 @@ protected:
...
@@ -103,6 +106,15 @@ protected:
fflush
(
target_file_
);
fflush
(
target_file_
);
}
}
private:
void
_print_ccode
(
const
std
::
string
&
color_code
)
{
fwrite
(
color_code
.
data
(),
sizeof
(
char
),
color_code
.
size
(),
target_file_
);
}
void
_print_range
(
const
details
::
log_msg
&
msg
,
size_t
start
,
size_t
end
)
{
fwrite
(
msg
.
formatted
.
data
()
+
start
,
sizeof
(
char
),
end
-
start
,
target_file_
);
}
FILE
*
target_file_
;
FILE
*
target_file_
;
bool
should_do_colors_
;
bool
should_do_colors_
;
std
::
unordered_map
<
level
::
level_enum
,
std
::
string
,
level
::
level_hasher
>
colors_
;
std
::
unordered_map
<
level
::
level_enum
,
std
::
string
,
level
::
level_hasher
>
colors_
;
...
...
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