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
934a9bb2
Commit
934a9bb2
authored
Aug 30, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue #1617
parent
7097f7a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
7 deletions
+37
-7
include/spdlog/pattern_formatter-inl.h
include/spdlog/pattern_formatter-inl.h
+18
-3
tests/test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+19
-4
No files found.
include/spdlog/pattern_formatter-inl.h
View file @
934a9bb2
...
...
@@ -1246,9 +1246,24 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
default:
// Unknown flag appears as is
auto
unknown_flag
=
details
::
make_unique
<
details
::
aggregate_formatter
>
();
unknown_flag
->
add_ch
(
'%'
);
unknown_flag
->
add_ch
(
flag
);
formatters_
.
push_back
((
std
::
move
(
unknown_flag
)));
if
(
!
padding
.
truncate_
)
{
unknown_flag
->
add_ch
(
'%'
);
unknown_flag
->
add_ch
(
flag
);
formatters_
.
push_back
((
std
::
move
(
unknown_flag
)));
}
// fix issue #1617 (prev char was '!' and should have been treated as funcname flag instead of truncating flag)
// spdlog::set_pattern("[%10!] %v") => "[ main] some message"
// spdlog::set_pattern("[%3!!] %v") => "[mai] some message"
else
{
padding
.
truncate_
=
false
;
formatters_
.
push_back
(
details
::
make_unique
<
details
::
source_funcname_formatter
<
Padder
>>
(
padding
));
unknown_flag
->
add_ch
(
flag
);
formatters_
.
push_back
((
std
::
move
(
unknown_flag
)));
}
break
;
}
}
...
...
tests/test_pattern_formatter.cpp
View file @
934a9bb2
...
...
@@ -227,7 +227,7 @@ TEST_CASE("paddinng_truncate", "[pattern_formatter]")
REQUIRE
(
log_to_str
(
"123456"
,
"%0!v"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
)
==
"
\n
"
);
}
TEST_CASE
(
"paddin
n
g_truncate_funcname"
,
"[pattern_formatter]"
)
TEST_CASE
(
"padding_truncate_funcname"
,
"[pattern_formatter]"
)
{
spdlog
::
sinks
::
test_sink_st
test_sink
;
...
...
@@ -237,13 +237,28 @@ TEST_CASE("paddinng_truncate_funcname", "[pattern_formatter]")
spdlog
::
details
::
log_msg
msg1
{
spdlog
::
source_loc
{
"ignored"
,
1
,
"func"
},
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
test_sink
.
log
(
msg1
);
REQUIRE
(
test_sink
.
lines
()[
0
]
==
"message [ func]"
);
spdlog
::
details
::
log_msg
msg2
{
spdlog
::
source_loc
{
"ignored"
,
1
,
"function"
},
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
test_sink
.
log
(
msg2
);
REQUIRE
(
test_sink
.
lines
()[
1
]
==
"message [funct]"
);
}
TEST_CASE
(
"padding_funcname"
,
"[pattern_formatter]"
)
{
spdlog
::
sinks
::
test_sink_st
test_sink
;
auto
lines
=
test_sink
.
lines
();
REQUIRE
(
lines
[
0
]
==
"message [ func]"
);
REQUIRE
(
lines
[
1
]
==
"message [funct]"
);
const
char
*
pattern
=
"%v [%10!]"
;
auto
formatter
=
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
spdlog
::
pattern_formatter
(
pattern
));
test_sink
.
set_formatter
(
std
::
move
(
formatter
));
spdlog
::
details
::
log_msg
msg1
{
spdlog
::
source_loc
{
"ignored"
,
1
,
"func"
},
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
test_sink
.
log
(
msg1
);
REQUIRE
(
test_sink
.
lines
()[
0
]
==
"message [ func]"
);
spdlog
::
details
::
log_msg
msg2
{
spdlog
::
source_loc
{
"ignored"
,
1
,
"func567890123"
},
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
test_sink
.
log
(
msg2
);
REQUIRE
(
test_sink
.
lines
()[
1
]
==
"message [func567890123]"
);
}
TEST_CASE
(
"clone-default-formatter"
,
"[pattern_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