Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
7ee62814
Commit
7ee62814
authored
8 years ago
by
Simon Désaulniers
Committed by
Adrien Béraud
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
log: display time before each line in log
parent
28a5740c
Branches
log-with-time
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/opendht/log.h
+16
-5
16 additions, 5 deletions
include/opendht/log.h
with
16 additions
and
5 deletions
include/opendht/log.h
+
16
−
5
View file @
7ee62814
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include
<iostream>
#include
<iostream>
#include
<fstream>
#include
<fstream>
#include
<chrono>
namespace
dht
{
namespace
dht
{
namespace
log
{
namespace
log
{
...
@@ -63,13 +64,23 @@ constexpr const Color::Modifier yellow(Color::FG_YELLOW);
...
@@ -63,13 +64,23 @@ constexpr const Color::Modifier yellow(Color::FG_YELLOW);
*/
*/
void
void
printLog
(
std
::
ostream
&
s
,
char
const
*
m
,
va_list
args
)
{
printLog
(
std
::
ostream
&
s
,
char
const
*
m
,
va_list
args
)
{
static
constex
pr
int
BUF_SZ
=
8192
;
//
print
log to buffer
char
buffer
[
BUF_SZ
]
;
std
::
array
<
char
,
8192
>
buffer
;
int
ret
=
vsnprintf
(
buffer
,
sizeof
(
buffer
),
m
,
args
);
int
ret
=
vsnprintf
(
buffer
.
data
(),
buffer
.
size
(
),
m
,
args
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
;
return
;
s
.
write
(
buffer
,
std
::
min
(
ret
,
BUF_SZ
));
if
(
ret
>=
BUF_SZ
)
// write timestamp
using
namespace
std
::
chrono
;
using
log_precision
=
microseconds
;
constexpr
auto
den
=
log_precision
::
period
::
den
;
auto
micro
=
duration_cast
<
log_precision
>
(
steady_clock
::
now
().
time_since_epoch
()).
count
();
s
<<
"["
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
micro
/
den
<<
"."
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
micro
%
den
<<
"]"
<<
" "
;
// write log
s
.
write
(
buffer
.
data
(),
std
::
min
((
size_t
)
ret
,
buffer
.
size
()));
if
((
size_t
)
ret
>=
buffer
.
size
())
s
<<
"[[TRUNCATED]]"
;
s
<<
"[[TRUNCATED]]"
;
s
.
put
(
'\n'
);
s
.
put
(
'\n'
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment