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
de6ddf4e
Commit
de6ddf4e
authored
Jul 26, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some code refactoring in formatter
parent
a12a21a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
11 deletions
+22
-11
include/spdlog/details/fmt_helper.h
include/spdlog/details/fmt_helper.h
+15
-0
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+7
-11
No files found.
include/spdlog/details/fmt_helper.h
View file @
de6ddf4e
...
...
@@ -4,6 +4,9 @@
#pragma once
#include "chrono"
#include "spdlog/fmt/fmt.h"
// Some fmt helpers to efficiently format and pad ints and strings
namespace
spdlog
{
namespace
details
{
...
...
@@ -110,6 +113,18 @@ inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
pad3
(
static_cast
<
int
>
(
n
%
1000
),
dest
);
}
// return fraction of a second of the given time_point.
// e.g.
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
template
<
typename
ToDuration
>
ToDuration
time_fraction
(
const
log_clock
::
time_point
&
tp
)
{
using
namespace
std
::
chrono
;
auto
duration
=
tp
.
time_since_epoch
();
auto
secs
=
duration_cast
<
seconds
>
(
duration
);
return
duration_cast
<
ToDuration
>
(
duration
)
-
duration_cast
<
ToDuration
>
(
secs
);
}
}
// namespace fmt_helper
}
// namespace details
}
// namespace spdlog
\ No newline at end of file
include/spdlog/details/pattern_formatter.h
View file @
de6ddf4e
...
...
@@ -231,10 +231,7 @@ class e_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
using
namespace
std
::
chrono
;
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
secs
=
duration_cast
<
seconds
>
(
duration
);
auto
millis
=
duration_cast
<
milliseconds
>
(
duration
)
-
duration_cast
<
milliseconds
>
(
secs
);
auto
millis
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
milliseconds
>
(
msg
.
time
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
.
count
()),
dest
);
}
};
...
...
@@ -244,9 +241,8 @@ class f_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
micros
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
duration
).
count
()
%
1000000
;
fmt_helper
::
pad6
(
static_cast
<
int
>
(
micros
),
dest
);
auto
micros
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
microseconds
>
(
msg
.
time
);
fmt_helper
::
pad6
(
static_cast
<
int
>
(
micros
.
count
()),
dest
);
}
};
...
...
@@ -255,12 +251,12 @@ class F_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
ns
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
duration
).
count
()
%
1000000000
;
fmt
::
format_to
(
dest
,
"{:09}"
,
ns
);
auto
ns
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
nanoseconds
>
(
msg
.
time
);
fmt
::
format_to
(
dest
,
"{:09}"
,
ns
.
count
());
}
};
// seconds since epoch
class
E_formatter
SPDLOG_FINAL
:
public
flag_formatter
{
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
...
...
@@ -499,7 +495,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
}
fmt_helper
::
append_buf
(
cached_datetime_
,
dest
);
auto
millis
=
duration_cast
<
milliseconds
>
(
duration
)
-
duration_cast
<
milliseconds
>
(
secs
);
auto
millis
=
fmt_helper
::
time_fraction
<
milliseconds
>
(
msg
.
time
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
.
count
()),
dest
);
dest
.
push_back
(
']'
);
dest
.
push_back
(
' '
);
...
...
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