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
2894e8de
Commit
2894e8de
authored
Jul 24, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang format
parent
74c10df1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
41 deletions
+43
-41
Makefile
bench/Makefile
+1
-1
example.cpp
example/example.cpp
+4
-3
async.h
include/spdlog/async.h
+5
-5
periodic_worker.h
include/spdlog/details/periodic_worker.h
+9
-9
registry.h
include/spdlog/details/registry.h
+22
-22
spdlog.h
include/spdlog/spdlog.h
+2
-1
No files found.
bench/Makefile
View file @
2894e8de
CXX
?=
g++
CXX
?=
g++
CXXFLAGS
=
-march
=
native
-Wall
-Wextra
-pedantic
-std
=
c++11
-pthread
-I
../include
-fmax-errors
=
1
CXXFLAGS
=
-march
=
native
-Wall
-Wextra
-pedantic
-std
=
c++11
-pthread
-I
../include
-fmax-errors
=
1
CXX_RELEASE_FLAGS
=
-O3
-flto
-Wl
,--no-as-needed
CXX_RELEASE_FLAGS
=
-O3
-flto
-Wl
,--no-as-needed
binaries
=
bench latency
binaries
=
bench latency
...
...
example/example.cpp
View file @
2894e8de
...
@@ -23,6 +23,7 @@ void syslog_example();
...
@@ -23,6 +23,7 @@ void syslog_example();
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
{
try
try
{
{
// console logging example
// console logging example
...
@@ -52,8 +53,8 @@ int main(int, char *[])
...
@@ -52,8 +53,8 @@ int main(int, char *[])
// apply some function on all registered loggers
// apply some function on all registered loggers
spdlog
::
apply_all
([
&
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
{
l
->
info
(
"End of example."
);
});
spdlog
::
apply_all
([
&
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
{
l
->
info
(
"End of example."
);
});
//
Release and close all loggers
//
release any threads created by spdlog, and drop all loggers in the registry.
spdlog
::
drop_all
();
spdlog
::
shutdown
();
}
}
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
catch
(
const
spdlog
::
spdlog_ex
&
ex
)
catch
(
const
spdlog
::
spdlog_ex
&
ex
)
...
@@ -69,7 +70,7 @@ void stdout_example()
...
@@ -69,7 +70,7 @@ void stdout_example()
{
{
// create color multi threaded logger
// create color multi threaded logger
auto
console
=
spdlog
::
stdout_color_mt
(
"console"
);
auto
console
=
spdlog
::
stdout_color_mt
(
"console"
);
console
->
info
(
"Welcome to spdlog
!"
);
console
->
info
(
"Welcome to spdlog
version {}.{}.{} !"
,
SPDLOG_VER_MAJOR
,
SPDLOG_VER_MINOR
,
SPDLOG_VER_PATCH
);
console
->
error
(
"Some error message with arg: {}"
,
1
);
console
->
error
(
"Some error message with arg: {}"
,
1
);
auto
err_logger
=
spdlog
::
stderr_color_mt
(
"stderr"
);
auto
err_logger
=
spdlog
::
stderr_color_mt
(
"stderr"
);
...
...
include/spdlog/async.h
View file @
2894e8de
...
@@ -38,11 +38,11 @@ struct async_factory_impl
...
@@ -38,11 +38,11 @@ struct async_factory_impl
template
<
typename
Sink
,
typename
...
SinkArgs
>
template
<
typename
Sink
,
typename
...
SinkArgs
>
static
std
::
shared_ptr
<
async_logger
>
create
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
args
)
static
std
::
shared_ptr
<
async_logger
>
create
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
args
)
{
{
using
details
::
registry
;
using
details
::
registry
;
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
// create default tp if not already exists.
// create default tp if not already exists.
auto
tp
=
registry
::
instance
().
create_tp_once
(
details
::
default_async_q_size
,
1
);
auto
tp
=
registry
::
instance
().
create_tp_once
(
details
::
default_async_q_size
,
1
);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
std
::
move
(
sink
),
std
::
move
(
tp
),
OverflowPolicy
);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
std
::
move
(
sink
),
std
::
move
(
tp
),
OverflowPolicy
);
registry
::
instance
().
register_and_init
(
new_logger
);
registry
::
instance
().
register_and_init
(
new_logger
);
return
new_logger
;
return
new_logger
;
...
@@ -66,9 +66,9 @@ inline std::shared_ptr<spdlog::logger> create_async_nb(const std::string &logger
...
@@ -66,9 +66,9 @@ inline std::shared_ptr<spdlog::logger> create_async_nb(const std::string &logger
// set global thread pool.
// set global thread pool.
inline
void
init_thread_pool
(
size_t
q_size
,
size_t
thread_count
)
inline
void
init_thread_pool
(
size_t
q_size
,
size_t
thread_count
)
{
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
q_size
,
thread_count
);
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
q_size
,
thread_count
);
details
::
registry
::
instance
().
set_tp
(
std
::
move
(
tp
));
details
::
registry
::
instance
().
set_tp
(
std
::
move
(
tp
));
}
}
// get the global thread pool.
// get the global thread pool.
...
...
include/spdlog/details/periodic_worker.h
View file @
2894e8de
...
@@ -50,15 +50,15 @@ public:
...
@@ -50,15 +50,15 @@ public:
// stop the worker thread and join it
// stop the worker thread and join it
~
periodic_worker
()
~
periodic_worker
()
{
{
if
(
worker_thread_
.
joinable
())
if
(
worker_thread_
.
joinable
())
{
{
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
active_
=
false
;
active_
=
false
;
}
}
cv_
.
notify_one
();
cv_
.
notify_one
();
worker_thread_
.
join
();
worker_thread_
.
join
();
}
}
}
}
private
:
private
:
...
...
include/spdlog/details/registry.h
View file @
2894e8de
...
@@ -72,16 +72,16 @@ public:
...
@@ -72,16 +72,16 @@ public:
tp_
=
std
::
move
(
tp
);
tp_
=
std
::
move
(
tp
);
}
}
// create tp only if not exists already
// create tp only if not exists already
std
::
shared_ptr
<
thread_pool
>
create_tp_once
(
size_t
queue_size
,
size_t
n_threads
)
std
::
shared_ptr
<
thread_pool
>
create_tp_once
(
size_t
queue_size
,
size_t
n_threads
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
tp_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
tp_mutex_
);
if
(
tp_
==
nullptr
)
if
(
tp_
==
nullptr
)
{
{
tp_
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
n_threads
);
tp_
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
n_threads
);
}
}
return
tp_
;
return
tp_
;
}
}
std
::
shared_ptr
<
thread_pool
>
get_tp
()
std
::
shared_ptr
<
thread_pool
>
get_tp
()
{
{
...
@@ -146,14 +146,14 @@ public:
...
@@ -146,14 +146,14 @@ public:
}
}
}
}
void
flush_all
()
void
flush_all
()
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
{
{
l
.
second
->
flush
();
l
.
second
->
flush
();
}
}
}
}
void
drop
(
const
std
::
string
&
logger_name
)
void
drop
(
const
std
::
string
&
logger_name
)
{
{
...
@@ -175,14 +175,14 @@ public:
...
@@ -175,14 +175,14 @@ public:
periodic_flusher_
.
reset
();
periodic_flusher_
.
reset
();
}
}
drop_all
();
drop_all
();
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
tp_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
tp_mutex_
);
tp_
.
reset
();
tp_
.
reset
();
}
}
}
}
static
registry
&
instance
()
static
registry
&
instance
()
{
{
static
registry
s_instance
;
static
registry
s_instance
;
...
@@ -208,10 +208,10 @@ private:
...
@@ -208,10 +208,10 @@ private:
throw
spdlog_ex
(
"logger with name '"
+
logger_name
+
"' already exists"
);
throw
spdlog_ex
(
"logger with name '"
+
logger_name
+
"' already exists"
);
}
}
}
}
std
::
mutex
logger_map_mutex_
,
flusher_mutex_
;
std
::
mutex
logger_map_mutex_
,
flusher_mutex_
;
std
::
mutex
tp_mutex_
;
std
::
mutex
tp_mutex_
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
loggers_
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
loggers_
;
std
::
unique_ptr
<
formatter
>
formatter_
;
std
::
unique_ptr
<
formatter
>
formatter_
;
level
::
level_enum
level_
=
level
::
info
;
level
::
level_enum
level_
=
level
::
info
;
level
::
level_enum
flush_level_
=
level
::
off
;
level
::
level_enum
flush_level_
=
level
::
off
;
...
...
include/spdlog/spdlog.h
View file @
2894e8de
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "spdlog/common.h"
#include "spdlog/common.h"
#include "spdlog/details/registry.h"
#include "spdlog/details/registry.h"
#include "spdlog/logger.h"
#include "spdlog/logger.h"
#include "spdlog/version.h"
#include <chrono>
#include <chrono>
#include <functional>
#include <functional>
...
@@ -120,7 +121,7 @@ inline void drop_all()
...
@@ -120,7 +121,7 @@ inline void drop_all()
// stop any running threads started by spdlog and clean registry loggers
// stop any running threads started by spdlog and clean registry loggers
inline
void
shutdown
()
inline
void
shutdown
()
{
{
details
::
registry
::
instance
().
shutdown
();
details
::
registry
::
instance
().
shutdown
();
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
...
...
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