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
035a8ff0
Commit
035a8ff0
authored
Sep 17, 2021
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added logger::set_formatter template overload
parent
aa14b833
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
4 deletions
+11
-4
example/example.cpp
example/example.cpp
+3
-3
include/spdlog/logger.h
include/spdlog/logger.h
+7
-0
tests/test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+1
-1
No files found.
example/example.cpp
View file @
035a8ff0
...
...
@@ -51,9 +51,9 @@ int main(int, char *[])
spdlog
::
debug
(
"This message should be displayed.."
);
// Customize msg format
spdlog
::
default_logger
()
->
set_formatter
(
make_unique
<
spdlog
::
pattern_formatter
>
(
"[%H:%M:%S %z] [%^%L%$] [thread %t] %v"
)
);
spdlog
::
default_logger
()
->
set_formatter
<
spdlog
::
pattern_formatter
>
(
"[%H:%M:%S %z] [%^%L%$] [thread %t] %v"
);
spdlog
::
info
(
"This an info message with custom format"
);
spdlog
::
default_logger
()
->
set_formatter
(
make_unique
<
spdlog
::
default_formatter
>
()
);
// back to default format
spdlog
::
default_logger
()
->
set_formatter
<
spdlog
::
default_formatter
>
(
);
// back to default format
spdlog
::
default_logger
()
->
set_level
(
spdlog
::
level
::
info
);
try
...
...
@@ -285,7 +285,7 @@ public:
std
::
unique_ptr
<
custom_flag_formatter
>
clone
()
const
override
{
return
spdlog
::
details
::
make_unique
<
my_formatter_flag
>
();
return
make_unique
<
my_formatter_flag
>
();
}
};
...
...
include/spdlog/logger.h
View file @
035a8ff0
...
...
@@ -279,6 +279,13 @@ public:
// each sink will get a separate instance of the formatter object.
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
f
);
template
<
typename
Formatter
,
typename
...
Args
>
void
set_formatter
(
Args
&&
...
args
)
{
set_formatter
(
details
::
make_unique
<
Formatter
>
(
std
::
forward
<
Args
>
(
args
)...));
}
// flush functions
void
flush
();
void
flush_on
(
level
::
level_enum
log_level
);
...
...
tests/test_pattern_formatter.cpp
View file @
035a8ff0
...
...
@@ -12,7 +12,7 @@ static std::string log_to_str(const std::string &msg, const Args &... args)
spdlog
::
logger
oss_logger
(
"pattern_tester"
,
oss_sink
);
oss_logger
.
set_level
(
spdlog
::
level
::
info
);
oss_logger
.
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
spdlog
::
pattern_formatter
(
args
...))
);
oss_logger
.
set_formatter
<
spdlog
::
pattern_formatter
>
(
args
...
);
oss_logger
.
info
(
msg
);
return
oss
.
str
();
...
...
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