Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
6400b188
Commit
6400b188
authored
Feb 05, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
timestamp caching of last second
parent
52dc317c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
formatters.cpp
src/formatters.cpp
+19
-11
No files found.
src/formatters.cpp
View file @
6400b188
#include "stdafx.h"
#include <memory.h>
#include "c11log/formatters/formatters.h"
#include "c11log/level.h"
void
c11log
::
formatters
::
format_time
(
const
c11log
::
formatters
::
timepoint
&
tp
,
std
::
ostream
&
dest
)
{
std
::
tm
tm
=
details
::
os
::
localtime
(
std
::
chrono
::
system_clock
::
to_time_t
(
tp
));
//get ms
//auto duration = tp.time_since_epoch();
//int millis = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000);
static
thread_local
std
::
tm
last_tm
;
static
thread_local
char
timestamp_cache
[
64
];
char
buf
[
64
];
auto
size
=
sprintf
(
buf
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
void
c11log
::
formatters
::
format_time
(
const
c11log
::
formatters
::
timepoint
&
tp
,
std
::
ostream
&
dest
)
{
dest
.
write
(
buf
,
size
);
auto
tm
=
details
::
os
::
localtime
(
std
::
chrono
::
system_clock
::
to_time_t
(
tp
));
// Cache timestamp string of last second
if
(
memcmp
(
&
tm
,
&
last_tm
,
sizeof
(
tm
)))
{
sprintf
(
timestamp_cache
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
last_tm
=
tm
;
}
dest
<<
timestamp_cache
;
}
void
c11log
::
formatters
::
format_time
(
std
::
ostream
&
dest
)
...
...
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