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
65cff673
Commit
65cff673
authored
Nov 11, 2018
by
gabime
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v1.x' of
https://github.com/gabime/spdlog
into v1.x
parents
dc166cad
99b68c83
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
9 deletions
+38
-9
include/spdlog/async.h
include/spdlog/async.h
+1
-1
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+13
-7
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+7
-1
tests/test_registry.cpp
tests/test_registry.cpp
+17
-0
No files found.
include/spdlog/async.h
View file @
65cff673
...
@@ -52,7 +52,7 @@ struct async_factory_impl
...
@@ -52,7 +52,7 @@ struct async_factory_impl
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
std
::
move
(
logger_name
),
std
::
move
(
sink
),
std
::
move
(
tp
),
OverflowPolicy
);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
std
::
move
(
logger_name
),
std
::
move
(
sink
),
std
::
move
(
tp
),
OverflowPolicy
);
registry_inst
.
register_and_init
(
new_logger
);
registry_inst
.
initialize_logger
(
new_logger
);
return
new_logger
;
return
new_logger
;
}
}
};
};
...
...
include/spdlog/details/registry.h
View file @
65cff673
...
@@ -47,13 +47,9 @@ public:
...
@@ -47,13 +47,9 @@ public:
loggers_
[
logger_name
]
=
std
::
move
(
new_logger
);
loggers_
[
logger_name
]
=
std
::
move
(
new_logger
);
}
}
void
register_and_init
(
std
::
shared_ptr
<
logger
>
new_logger
)
void
initialize_logger
(
std
::
shared_ptr
<
logger
>
new_logger
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
auto
logger_name
=
new_logger
->
name
();
throw_if_exists_
(
logger_name
);
// set the global formatter pattern
new_logger
->
set_formatter
(
formatter_
->
clone
());
new_logger
->
set_formatter
(
formatter_
->
clone
());
if
(
err_handler_
)
if
(
err_handler_
)
...
@@ -64,8 +60,11 @@ public:
...
@@ -64,8 +60,11 @@ public:
new_logger
->
set_level
(
level_
);
new_logger
->
set_level
(
level_
);
new_logger
->
flush_on
(
flush_level_
);
new_logger
->
flush_on
(
flush_level_
);
// add to registry
if
(
automatic_registration_
)
loggers_
[
logger_name
]
=
std
::
move
(
new_logger
);
{
throw_if_exists_
(
new_logger
->
name
());
loggers_
[
new_logger
->
name
()]
=
std
::
move
(
new_logger
);
}
}
}
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
logger_name
)
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
logger_name
)
...
@@ -223,6 +222,12 @@ public:
...
@@ -223,6 +222,12 @@ public:
return
tp_mutex_
;
return
tp_mutex_
;
}
}
void
set_automatic_registration
(
bool
automatic_regsistration
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
automatic_registration_
=
automatic_regsistration
;
}
static
registry
&
instance
()
static
registry
&
instance
()
{
{
static
registry
s_instance
;
static
registry
s_instance
;
...
@@ -269,6 +274,7 @@ private:
...
@@ -269,6 +274,7 @@ private:
std
::
shared_ptr
<
thread_pool
>
tp_
;
std
::
shared_ptr
<
thread_pool
>
tp_
;
std
::
unique_ptr
<
periodic_worker
>
periodic_flusher_
;
std
::
unique_ptr
<
periodic_worker
>
periodic_flusher_
;
std
::
shared_ptr
<
logger
>
default_logger_
;
std
::
shared_ptr
<
logger
>
default_logger_
;
bool
automatic_registration_
=
true
;
};
};
}
// namespace details
}
// namespace details
...
...
include/spdlog/spdlog.h
View file @
65cff673
...
@@ -29,7 +29,7 @@ struct synchronous_factory
...
@@ -29,7 +29,7 @@ struct synchronous_factory
{
{
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
new_logger
=
std
::
make_shared
<
logger
>
(
std
::
move
(
logger_name
),
std
::
move
(
sink
));
auto
new_logger
=
std
::
make_shared
<
logger
>
(
std
::
move
(
logger_name
),
std
::
move
(
sink
));
details
::
registry
::
instance
().
register_and_init
(
new_logger
);
details
::
registry
::
instance
().
initialize_logger
(
new_logger
);
return
new_logger
;
return
new_logger
;
}
}
};
};
...
@@ -125,6 +125,12 @@ inline void shutdown()
...
@@ -125,6 +125,12 @@ inline void shutdown()
details
::
registry
::
instance
().
shutdown
();
details
::
registry
::
instance
().
shutdown
();
}
}
// Automatic registration of loggers when using spdlog::create() or spdlog::create_async
inline
void
set_automatic_registration
(
bool
automatic_registation
)
{
details
::
registry
::
instance
().
set_automatic_registration
(
automatic_registation
);
}
// API for using default logger (stdout_color_mt),
// API for using default logger (stdout_color_mt),
// e.g: spdlog::info("Message {}", 1);
// e.g: spdlog::info("Message {}", 1);
//
//
...
...
tests/test_registry.cpp
View file @
65cff673
...
@@ -93,3 +93,20 @@ TEST_CASE("set_default_logger(nullptr)", "[registry]")
...
@@ -93,3 +93,20 @@ TEST_CASE("set_default_logger(nullptr)", "[registry]")
spdlog
::
set_default_logger
(
nullptr
);
spdlog
::
set_default_logger
(
nullptr
);
REQUIRE_FALSE
(
spdlog
::
default_logger
());
REQUIRE_FALSE
(
spdlog
::
default_logger
());
}
}
TEST_CASE
(
"disable automatic registration"
,
"[registry]"
)
{
// set some global parameters
spdlog
::
level
::
level_enum
log_level
=
spdlog
::
level
::
level_enum
::
warn
;
spdlog
::
set_level
(
log_level
);
// but disable automatic registration
spdlog
::
set_automatic_registration
(
false
);
auto
logger1
=
spdlog
::
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
tested_logger_name
,
"filename"
,
11
,
59
);
auto
logger2
=
spdlog
::
create_async
<
spdlog
::
sinks
::
stdout_color_sink_mt
>
(
tested_logger_name2
);
// loggers should not be part of the registry
REQUIRE_FALSE
(
spdlog
::
get
(
tested_logger_name
));
REQUIRE_FALSE
(
spdlog
::
get
(
tested_logger_name2
));
// but make sure they are still initialized according to global defaults
REQUIRE
(
logger1
->
level
()
==
log_level
);
REQUIRE
(
logger2
->
level
()
==
log_level
);
}
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