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
ed8d0996
Commit
ed8d0996
authored
Aug 29, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #1197
parent
b693d0cd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
2 deletions
+70
-2
include/spdlog/async_logger-inl.h
include/spdlog/async_logger-inl.h
+7
-0
include/spdlog/async_logger.h
include/spdlog/async_logger.h
+2
-0
include/spdlog/fmt/bin_to_hex.h
include/spdlog/fmt/bin_to_hex.h
+0
-1
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+8
-0
include/spdlog/logger.h
include/spdlog/logger.h
+3
-0
tests/test_misc.cpp
tests/test_misc.cpp
+50
-1
No files found.
include/spdlog/async_logger-inl.h
View file @
ed8d0996
...
@@ -83,3 +83,10 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
...
@@ -83,3 +83,10 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
SPDLOG_LOGGER_CATCH
()
SPDLOG_LOGGER_CATCH
()
}
}
}
}
SPDLOG_INLINE
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
async_logger
::
clone
(
std
::
string
new_name
)
{
auto
cloned
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
*
this
);
cloned
->
name_
=
std
::
move
(
new_name
);
return
cloned
;
}
include/spdlog/async_logger.h
View file @
ed8d0996
...
@@ -49,6 +49,8 @@ public:
...
@@ -49,6 +49,8 @@ public:
async_logger
(
std
::
string
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_logger
(
std
::
string
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
std
::
shared_ptr
<
logger
>
clone
(
std
::
string
new_name
)
override
;
protected:
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
;
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
;
void
flush_
()
override
;
void
flush_
()
override
;
...
...
include/spdlog/fmt/bin_to_hex.h
View file @
ed8d0996
...
@@ -122,7 +122,6 @@ struct formatter<spdlog::details::bytes_range<T>>
...
@@ -122,7 +122,6 @@ struct formatter<spdlog::details::bytes_range<T>>
auto
inserter
=
ctx
.
out
();
auto
inserter
=
ctx
.
out
();
#endif
#endif
for
(
auto
&
item
:
the_range
)
for
(
auto
&
item
:
the_range
)
{
{
auto
ch
=
static_cast
<
unsigned
char
>
(
item
);
auto
ch
=
static_cast
<
unsigned
char
>
(
item
);
...
...
include/spdlog/logger-inl.h
View file @
ed8d0996
...
@@ -162,6 +162,14 @@ SPDLOG_INLINE void logger::set_error_handler(err_handler handler)
...
@@ -162,6 +162,14 @@ SPDLOG_INLINE void logger::set_error_handler(err_handler handler)
custom_err_handler_
=
handler
;
custom_err_handler_
=
handler
;
}
}
// create new logger with same sinks and configuration.
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
logger
::
clone
(
std
::
string
logger_name
)
{
auto
cloned
=
std
::
make_shared
<
logger
>
(
*
this
);
cloned
->
name_
=
std
::
move
(
logger_name
);
return
cloned
;
}
// protected methods
// protected methods
SPDLOG_INLINE
void
logger
::
sink_it_
(
const
details
::
log_msg
&
msg
)
SPDLOG_INLINE
void
logger
::
sink_it_
(
const
details
::
log_msg
&
msg
)
{
{
...
...
include/spdlog/logger.h
View file @
ed8d0996
...
@@ -356,6 +356,9 @@ public:
...
@@ -356,6 +356,9 @@ public:
// error handler
// error handler
void
set_error_handler
(
err_handler
);
void
set_error_handler
(
err_handler
);
// create new logger with same sinks and configuration.
virtual
std
::
shared_ptr
<
logger
>
clone
(
std
::
string
logger_name
);
protected:
protected:
std
::
string
name_
;
std
::
string
name_
;
std
::
vector
<
sink_ptr
>
sinks_
;
std
::
vector
<
sink_ptr
>
sinks_
;
...
...
tests/test_misc.cpp
View file @
ed8d0996
#include "includes.h"
#include "includes.h"
#include "test_sink.h"
#include "test_sink.h"
#include "spdlog/fmt/bin_to_hex.h"
template
<
class
T
>
template
<
class
T
>
std
::
string
log_info
(
const
T
&
what
,
spdlog
::
level
::
level_enum
logger_level
=
spdlog
::
level
::
info
)
std
::
string
log_info
(
const
T
&
what
,
spdlog
::
level
::
level_enum
logger_level
=
spdlog
::
level
::
info
)
...
@@ -92,7 +94,54 @@ TEST_CASE("periodic flush", "[periodic_flush]")
...
@@ -92,7 +94,54 @@ TEST_CASE("periodic flush", "[periodic_flush]")
spdlog
::
drop_all
();
spdlog
::
drop_all
();
}
}
#include "spdlog/fmt/bin_to_hex.h"
TEST_CASE
(
"clone-logger"
,
"[clone]"
)
{
using
namespace
spdlog
;
auto
test_sink
=
std
::
make_shared
<
sinks
::
test_sink_mt
>
();
auto
logger
=
std
::
make_shared
<
spdlog
::
logger
>
(
"orig"
,
test_sink
);
logger
->
set_pattern
(
"%v"
);
auto
cloned
=
logger
->
clone
(
"clone"
);
REQUIRE
(
cloned
->
name
()
==
"clone"
);
REQUIRE
(
logger
->
sinks
()
==
cloned
->
sinks
());
REQUIRE
(
logger
->
level
()
==
cloned
->
level
());
REQUIRE
(
logger
->
flush_level
()
==
cloned
->
flush_level
());
logger
->
info
(
"Some message 1"
);
cloned
->
info
(
"Some message 2"
);
REQUIRE
(
test_sink
->
lines
().
size
()
==
2
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"Some message 1"
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"Some message 2"
);
spdlog
::
drop_all
();
}
TEST_CASE
(
"clone async"
,
"[clone]"
)
{
using
namespace
spdlog
;
spdlog
::
init_thread_pool
(
4
,
1
);
auto
test_sink
=
std
::
make_shared
<
sinks
::
test_sink_st
>
();
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"orig"
,
test_sink
,
spdlog
::
thread_pool
());
logger
->
set_pattern
(
"%v"
);
auto
cloned
=
logger
->
clone
(
"clone"
);
REQUIRE
(
cloned
->
name
()
==
"clone"
);
REQUIRE
(
logger
->
sinks
()
==
cloned
->
sinks
());
REQUIRE
(
logger
->
level
()
==
cloned
->
level
());
REQUIRE
(
logger
->
flush_level
()
==
cloned
->
flush_level
());
logger
->
info
(
"Some message 1"
);
cloned
->
info
(
"Some message 2"
);
spdlog
::
details
::
os
::
sleep_for_millis
(
10
);
REQUIRE
(
test_sink
->
lines
().
size
()
==
2
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"Some message 1"
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"Some message 2"
);
spdlog
::
drop_all
();
}
TEST_CASE
(
"to_hex"
,
"[to_hex]"
)
TEST_CASE
(
"to_hex"
,
"[to_hex]"
)
{
{
...
...
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