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
c27a4ee6
Commit
c27a4ee6
authored
Jul 10, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added elapsed flag to formatter
parent
a4ec91fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
include/spdlog/details/pattern_formatter-inl.h
include/spdlog/details/pattern_formatter-inl.h
+50
-0
No files found.
include/spdlog/details/pattern_formatter-inl.h
View file @
c27a4ee6
...
...
@@ -888,6 +888,40 @@ public:
}
};
// print elapsed time since last message
template
<
typename
Units
>
class
elapsed_formatter
final
:
public
flag_formatter
{
public:
using
DurationUnits
=
Units
;
explicit
elapsed_formatter
(
padding_info
padinfo
)
:
flag_formatter
(
padinfo
),
last_message_time_
(
log_clock
::
now
())
{}
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
auto
delta
=
msg
.
time
-
last_message_time_
;
auto
delta_units
=
std
::
chrono
::
duration_cast
<
DurationUnits
>
(
delta
);
last_message_time_
=
msg
.
time
;
if
(
padinfo_
.
enabled
())
{
scoped_pad
p
(
6
,
padinfo_
,
dest
);
fmt_helper
::
pad6
(
static_cast
<
size_t
>
(
delta_units
.
count
()),
dest
);
}
else
{
fmt_helper
::
pad6
(
static_cast
<
size_t
>
(
delta_units
.
count
()),
dest
);
}
}
protected:
log_clock
::
time_point
last_message_time_
;
};
// Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
class
full_formatter
final
:
public
flag_formatter
...
...
@@ -1199,6 +1233,22 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
formatters_
.
push_back
(
details
::
make_unique
<
details
::
ch_formatter
>
(
'%'
));
break
;
case
(
'u'
):
// elapsed time since last log message in nanos
formatters_
.
push_back
(
details
::
make_unique
<
details
::
elapsed_formatter
<
std
::
chrono
::
nanoseconds
>>
(
padding
));
break
;
case
(
'i'
):
// elapsed time since last log message in micros
formatters_
.
push_back
(
details
::
make_unique
<
details
::
elapsed_formatter
<
std
::
chrono
::
microseconds
>>
(
padding
));
break
;
case
(
'o'
):
// elapsed time since last log message in millis
formatters_
.
push_back
(
details
::
make_unique
<
details
::
elapsed_formatter
<
std
::
chrono
::
milliseconds
>>
(
padding
));
break
;
case
(
'O'
):
// elapsed time since last log message in seconds
formatters_
.
push_back
(
details
::
make_unique
<
details
::
elapsed_formatter
<
std
::
chrono
::
seconds
>>
(
padding
));
break
;
default:
// Unknown flag appears as is
auto
unknown_flag
=
details
::
make_unique
<
details
::
aggregate_formatter
>
();
unknown_flag
->
add_ch
(
'%'
);
...
...
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