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
2f8e22d8
Commit
2f8e22d8
authored
Mar 22, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check if logger already exists in the registry before creating it
parent
becef922
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+15
-16
No files found.
include/spdlog/details/registry.h
View file @
2f8e22d8
...
...
@@ -33,7 +33,9 @@ public:
void
register_logger
(
std
::
shared_ptr
<
logger
>
logger
)
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
register_logger_impl
(
logger
);
auto
logger_name
=
logger
->
name
();
throw_if_exists
(
logger_name
);
_loggers
[
logger_name
]
=
logger
;
}
...
...
@@ -46,13 +48,10 @@ public:
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
>
new_logger
;
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
throw_if_exists
(
logger_name
);
std
::
shared_ptr
<
logger
>
new_logger
;
if
(
_async_mode
)
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
sinks_begin
,
sinks_end
,
_async_q_size
,
_overflow_policy
,
_worker_warmup_cb
,
_flush_interval_ms
);
else
...
...
@@ -62,7 +61,8 @@ public:
new_logger
->
set_formatter
(
_formatter
);
new_logger
->
set_level
(
_level
);
register_logger_impl
(
new_logger
);
//Add to registry
_loggers
[
logger_name
]
=
new_logger
;
return
new_logger
;
}
...
...
@@ -134,17 +134,16 @@ public:
return
s_instance
;
}
private:
void
register_logger_impl
(
std
::
shared_ptr
<
logger
>
logger
)
{
auto
logger_name
=
logger
->
name
();
if
(
_loggers
.
find
(
logger_name
)
!=
std
::
end
(
_loggers
))
throw
spdlog_ex
(
"logger with name "
+
logger_name
+
" already exists"
);
_loggers
[
logger
->
name
()]
=
logger
;
}
private:
registry_t
<
Mutex
>
()
{}
registry_t
<
Mutex
>
(
const
registry_t
<
Mutex
>&
)
=
delete
;
registry_t
<
Mutex
>&
operator
=
(
const
registry_t
<
Mutex
>&
)
=
delete
;
void
throw_if_exists
(
const
std
::
string
&
logger_name
)
{
if
(
_loggers
.
find
(
logger_name
)
!=
_loggers
.
end
())
throw
spdlog_ex
(
"logger with name '"
+
logger_name
+
"' already exists"
);
}
Mutex
_mutex
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
_loggers
;
formatter_ptr
_formatter
;
...
...
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