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
394f79e9
Commit
394f79e9
authored
Apr 15, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small refactoring
parent
595bbbd3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
60 deletions
+23
-60
include/spdlog/pattern_formatter-inl.h
include/spdlog/pattern_formatter-inl.h
+23
-60
No files found.
include/spdlog/pattern_formatter-inl.h
View file @
394f79e9
...
...
@@ -59,6 +59,12 @@ public:
}
}
template
<
typename
T
>
static
unsigned
int
count_digits
(
T
n
)
{
return
fmt_helper
::
count_digits
(
n
);
}
~
scoped_padder
()
{
if
(
remaining_pad_
>=
0
)
...
...
@@ -87,6 +93,9 @@ private:
struct
null_scoped_padder
{
null_scoped_padder
(
size_t
/*wrapped_size*/
,
const
padding_info
&
/*padinfo*/
,
memory_buf_t
&
/*dest*/
)
{}
template
<
typename
T
>
static
unsigned
int
count_digits
(
T
/* number */
)
{
return
0
;}
};
template
<
typename
ScopedPadder
>
...
...
@@ -638,26 +647,12 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
const
auto
field_size
=
fmt_help
er
::
count_digits
(
msg
.
thread_id
);
const
auto
field_size
=
ScopedPadd
er
::
count_digits
(
msg
.
thread_id
);
ScopedPadder
p
(
field_size
,
padinfo_
,
dest
);
fmt_helper
::
append_int
(
msg
.
thread_id
,
dest
);
}
};
// If padding is not needed, there is no need to count the digits of the thread id
template
<
>
class
t_formatter
<
null_scoped_padder
>
final
:
public
flag_formatter
{
public:
explicit
t_formatter
(
padding_info
padinfo
)
:
flag_formatter
(
padinfo
)
{}
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
fmt_helper
::
append_int
(
msg
.
thread_id
,
dest
);
}
};
// Current pid
template
<
typename
ScopedPadder
>
...
...
@@ -671,28 +666,12 @@ public:
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
const
auto
pid
=
static_cast
<
uint32_t
>
(
details
::
os
::
pid
());
auto
field_size
=
fmt_help
er
::
count_digits
(
pid
);
auto
field_size
=
ScopedPadd
er
::
count_digits
(
pid
);
ScopedPadder
p
(
field_size
,
padinfo_
,
dest
);
fmt_helper
::
append_int
(
pid
,
dest
);
}
};
// If padding is not needed, there is no need to count the digits of the pid
template
<
>
class
pid_formatter
<
null_scoped_padder
>
final
:
public
flag_formatter
{
public:
explicit
pid_formatter
(
padding_info
padinfo
)
:
flag_formatter
(
padinfo
)
{}
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
,
memory_buf_t
&
dest
)
override
{
const
auto
pid
=
static_cast
<
uint32_t
>
(
details
::
os
::
pid
());
fmt_helper
::
append_int
(
pid
,
dest
);
}
};
template
<
typename
ScopedPadder
>
class
v_formatter
final
:
public
flag_formatter
{
...
...
@@ -786,8 +765,16 @@ public:
return
;
}
size_t
text_size
=
padinfo_
.
enabled
()
?
std
::
char_traits
<
char
>::
length
(
msg
.
source
.
filename
)
+
fmt_helper
::
count_digits
(
msg
.
source
.
line
)
+
1
:
0
;
size_t
text_size
;
if
(
padinfo_
.
enabled
())
{
// calc text size for padding based on "filename:line"
text_size
=
std
::
char_traits
<
char
>::
length
(
msg
.
source
.
filename
)
+
ScopedPadder
::
count_digits
(
msg
.
source
.
line
)
+
1
;
}
else
{
text_size
=
0
;
}
ScopedPadder
p
(
text_size
,
padinfo_
,
dest
);
fmt_helper
::
append_string_view
(
msg
.
source
.
filename
,
dest
);
...
...
@@ -859,7 +846,7 @@ public:
return
;
}
auto
field_size
=
fmt_help
er
::
count_digits
(
msg
.
source
.
line
);
auto
field_size
=
ScopedPadd
er
::
count_digits
(
msg
.
source
.
line
);
ScopedPadder
p
(
field_size
,
padinfo_
,
dest
);
fmt_helper
::
append_int
(
msg
.
source
.
line
,
dest
);
}
...
...
@@ -904,7 +891,7 @@ public:
auto
delta_units
=
std
::
chrono
::
duration_cast
<
DurationUnits
>
(
delta
);
last_message_time_
=
msg
.
time
;
auto
delta_count
=
static_cast
<
size_t
>
(
delta_units
.
count
());
auto
n_digits
=
static_cast
<
size_t
>
(
fmt_help
er
::
count_digits
(
delta_count
));
auto
n_digits
=
static_cast
<
size_t
>
(
ScopedPadd
er
::
count_digits
(
delta_count
));
ScopedPadder
p
(
n_digits
,
padinfo_
,
dest
);
fmt_helper
::
append_int
(
delta_count
,
dest
);
}
...
...
@@ -913,30 +900,6 @@ private:
log_clock
::
time_point
last_message_time_
;
};
// If padding is not needed, there is no need to count the digits of the value
template
<
typename
Units
>
class
elapsed_formatter
<
null_scoped_padder
,
Units
>
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
&
,
memory_buf_t
&
dest
)
override
{
auto
delta
=
(
std
::
max
)(
msg
.
time
-
last_message_time_
,
log_clock
::
duration
::
zero
());
auto
delta_units
=
std
::
chrono
::
duration_cast
<
DurationUnits
>
(
delta
);
last_message_time_
=
msg
.
time
;
auto
delta_count
=
static_cast
<
size_t
>
(
delta_units
.
count
());
fmt_helper
::
append_int
(
delta_count
,
dest
);
}
private:
log_clock
::
time_point
last_message_time_
;
};
// Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
...
...
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