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
e3c333be
Commit
e3c333be
authored
Nov 24, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pattern_formatter - padding_info small refactor
parent
a1a46378
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
24 deletions
+40
-24
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+40
-24
No files found.
include/spdlog/details/pattern_formatter.h
View file @
e3c333be
...
...
@@ -41,6 +41,11 @@ struct padding_info
,
side_
(
side
)
{
}
bool
enabled
()
const
{
return
width_
!=
0
;
}
const
size_t
width_
=
0
;
const
pad_side
side_
=
left
;
};
...
...
@@ -130,10 +135,17 @@ public:
}
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
if
(
padinfo_
.
enabled
())
{
scoped_pad
p
(
*
msg
.
logger_name
,
padinfo_
,
dest
);
fmt_helper
::
append_string_view
(
*
msg
.
logger_name
,
dest
);
}
else
{
fmt_helper
::
append_string_view
(
*
msg
.
logger_name
,
dest
);
}
}
};
// log level appender
...
...
@@ -148,9 +160,16 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
string_view_t
level_name
{
level
::
to_c_str
(
msg
.
level
)};
if
(
padinfo_
.
enabled
())
{
scoped_pad
p
(
level_name
,
padinfo_
,
dest
);
fmt_helper
::
append_string_view
(
level_name
,
dest
);
}
else
{
fmt_helper
::
append_string_view
(
level_name
,
dest
);
}
}
};
// short log level appender
...
...
@@ -449,7 +468,7 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
auto
millis
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
milliseconds
>
(
msg
.
time
);
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
size_t
field_size
=
3
;
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -472,7 +491,7 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
auto
micros
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
microseconds
>
(
msg
.
time
);
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
size_t
field_size
=
6
;
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -495,7 +514,7 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
auto
ns
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
nanoseconds
>
(
msg
.
time
);
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
size_t
field_size
=
9
;
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -519,7 +538,6 @@ public:
{
const
size_t
field_size
=
10
;
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
seconds
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
duration
).
count
();
fmt_helper
::
append_int
(
seconds
,
dest
);
...
...
@@ -590,7 +608,6 @@ public:
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
const
size_t
field_size
=
8
;
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -670,7 +687,7 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
auto
field_size
=
fmt_helper
::
count_digits
(
msg
.
thread_id
);
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -693,7 +710,7 @@ public:
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
const
auto
pid
=
static_cast
<
uint32_t
>
(
details
::
os
::
pid
());
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
size_t
field_size
=
fmt
::
internal
::
count_digits
(
pid
);
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -729,7 +746,7 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
scoped_pad
p
(
msg
.
payload
,
padinfo_
,
dest
);
fmt_helper
::
append_string_view
(
msg
.
payload
,
dest
);
...
...
@@ -821,7 +838,7 @@ public:
{
return
;
}
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
auto
text_size
=
std
::
char_traits
<
char
>::
length
(
msg
.
source
.
filename
)
+
fmt_helper
::
count_digits
(
msg
.
source
.
line
)
+
1
;
scoped_pad
p
(
text_size
,
padinfo_
,
dest
);
...
...
@@ -867,7 +884,7 @@ public:
{
return
;
}
if
(
padinfo_
.
width_
)
if
(
padinfo_
.
enabled
()
)
{
const
size_t
field_size
=
fmt
::
internal
::
count_digits
(
msg
.
source
.
line
);
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
...
...
@@ -896,7 +913,6 @@ public:
using
std
::
chrono
::
milliseconds
;
using
std
::
chrono
::
seconds
;
#ifndef SPDLOG_NO_DATETIME
// cache the date/time part for the next second.
...
...
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