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
a12a21a1
Commit
a12a21a1
authored
Jul 25, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved millis formatting
parent
d8053dd6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
56 deletions
+24
-56
include/spdlog/details/fmt_helper.h
include/spdlog/details/fmt_helper.h
+10
-36
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+13
-19
include/spdlog/details/thread_pool.h
include/spdlog/details/thread_pool.h
+1
-1
No files found.
include/spdlog/details/fmt_helper.h
View file @
a12a21a1
...
...
@@ -68,11 +68,18 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
template
<
size_t
Buffer_Size
>
inline
void
pad3
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99
)
if
(
n
>
99
9
)
{
append_int
(
n
,
dest
);
return
;
}
if
(
n
>
99
)
// 100-999
{
append_int
(
n
/
100
,
dest
);
pad2
(
n
%
100
,
dest
);
return
;
}
if
(
n
>
9
)
// 10-99
{
dest
.
push_back
(
'0'
);
...
...
@@ -94,46 +101,13 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
template
<
size_t
Buffer_Size
>
inline
void
pad6
(
size_t
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
// todo: maybe replace this implementation with
// pad3(n / 1000, dest);
// pad3(n % 1000, dest);
if
(
n
>
99999
)
{
append_int
(
n
,
dest
);
return
;
}
if
(
n
>
9999
)
{
dest
.
push_back
(
'0'
);
}
else
if
(
n
>
999
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
if
(
n
>
99
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
if
(
n
>
9
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
// 0-9
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
append_int
(
n
,
dest
);
pad3
(
static_cast
<
int
>
(
n
/
1000
),
dest
);
pad3
(
static_cast
<
int
>
(
n
%
1000
),
dest
);
}
}
// namespace fmt_helper
...
...
include/spdlog/details/pattern_formatter.h
View file @
a12a21a1
...
...
@@ -69,7 +69,7 @@ static const char *ampm(const tm &t)
return
t
.
tm_hour
>=
12
?
"PM"
:
"AM"
;
}
static
int
to12h
(
const
tm
&
t
)
static
unsigned
int
to12h
(
const
tm
&
t
)
{
return
t
.
tm_hour
>
12
?
t
.
tm_hour
-
12
:
t
.
tm_hour
;
}
...
...
@@ -231,9 +231,11 @@ 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
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
dest
);
auto
secs
=
duration_cast
<
seconds
>
(
duration
);
auto
millis
=
duration_cast
<
milliseconds
>
(
duration
)
-
duration_cast
<
milliseconds
>
(
secs
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
.
count
()),
dest
);
}
};
...
...
@@ -464,13 +466,14 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
using
namespace
std
::
chrono
;
#ifndef SPDLOG_NO_DATETIME
// cache the date/time part for the next second.
auto
duration
=
msg
.
time
.
time_since_epoch
();
std
::
chrono
::
seconds
seconds
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
duration
);
auto
secs
=
duration_cast
<
seconds
>
(
duration
);
if
(
cache_timestamp_
!=
sec
ond
s
||
cached_datetime_
.
size
()
==
0
)
if
(
cache_timestamp_
!=
secs
||
cached_datetime_
.
size
()
==
0
)
{
cached_datetime_
.
resize
(
0
);
cached_datetime_
.
push_back
(
'['
);
...
...
@@ -492,22 +495,15 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
fmt_helper
::
pad2
(
tm_time
.
tm_sec
,
cached_datetime_
);
cached_datetime_
.
push_back
(
'.'
);
cache_timestamp_
=
sec
ond
s
;
cache_timestamp_
=
secs
;
}
fmt_helper
::
append_buf
(
cached_datetime_
,
dest
);
// cache the millis part for the next milli.
auto
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
if
(
millis
!=
millis_cache_timestamp_
||
cached_millis_
.
size
()
==
0
)
{
cached_millis_
.
resize
(
0
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
cached_millis_
);
cached_millis_
.
push_back
(
']'
);
cached_millis_
.
push_back
(
' '
);
millis_cache_timestamp_
=
millis
;
}
auto
millis
=
duration_cast
<
milliseconds
>
(
duration
)
-
duration_cast
<
milliseconds
>
(
secs
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
.
count
()),
dest
);
dest
.
push_back
(
']'
);
dest
.
push_back
(
' '
);
fmt_helper
::
append_buf
(
cached_millis_
,
dest
);
#else // no datetime needed
(
void
)
tm_time
;
#endif
...
...
@@ -531,9 +527,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
private:
std
::
chrono
::
seconds
cache_timestamp_
{
0
};
std
::
chrono
::
milliseconds
::
rep
millis_cache_timestamp_
{
0
};
fmt
::
basic_memory_buffer
<
char
,
128
>
cached_datetime_
;
fmt
::
basic_memory_buffer
<
char
,
8
>
cached_millis_
;
};
}
// namespace details
...
...
include/spdlog/details/thread_pool.h
View file @
a12a21a1
...
...
@@ -108,7 +108,7 @@ class thread_pool
{
public:
using
item_type
=
async_msg
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
thread_pool
(
size_t
q_max_items
,
size_t
threads_n
)
:
q_
(
q_max_items
)
...
...
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