Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
jami-daemon
Commits
e6885654
Commit
e6885654
authored
2 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
logger: use {fmt} for header generation
Change-Id: I3ee8a5051e8aace1737d40364bd5defae044636c
parent
a990260c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/logger.cpp
+15
-58
15 additions, 58 deletions
src/logger.cpp
with
15 additions
and
58 deletions
src/logger.cpp
+
15
−
58
View file @
e6885654
...
@@ -27,6 +27,11 @@
...
@@ -27,6 +27,11 @@
#include
"client/ring_signal.h"
#include
"client/ring_signal.h"
#include
<fmt/core.h>
#include
<fmt/format.h>
#include
<fmt/std.h>
#include
<fmt/compile.h>
#ifdef _MSC_VER
#ifdef _MSC_VER
#include
<sys_time.h>
#include
<sys_time.h>
#else
#else
...
@@ -38,8 +43,6 @@
...
@@ -38,8 +43,6 @@
#include
<functional>
#include
<functional>
#include
<fstream>
#include
<fstream>
#include
<string>
#include
<string>
#include
<sstream>
#include
<iomanip>
#include
<ios>
#include
<ios>
#include
<mutex>
#include
<mutex>
#include
<thread>
#include
<thread>
...
@@ -137,44 +140,14 @@ stripDirName(const char* path)
...
@@ -137,44 +140,14 @@ stripDirName(const char* path)
static
std
::
string
static
std
::
string
contextHeader
(
const
char
*
const
file
,
int
line
)
contextHeader
(
const
char
*
const
file
,
int
line
)
{
{
static
char
*
timestamp_fmt
=
getenv
(
"JAMI_TIMESTAMP_FMT"
);
#ifdef __linux__
#ifdef __linux__
auto
tid
=
syscall
(
__NR_gettid
)
&
0xffff
;
auto
tid
=
syscall
(
__NR_gettid
)
&
0xffff
;
#else
#else
auto
tid
=
std
::
this_thread
::
get_id
();
auto
tid
=
std
::
this_thread
::
get_id
();
#endif // __linux__
#endif // __linux__
std
::
ostringstream
out
;
out
<<
'['
;
// Timestamp
if
(
timestamp_fmt
)
{
time_t
t
;
struct
tm
tm
;
char
buf
[
128
];
time
(
&
t
);
#ifdef _WIN32
/* NOTE! localtime(3) is MT-Safe on win32 */
tm
=
*
localtime
(
&
t
);
#else
localtime_r
(
&
t
,
&
tm
);
#endif
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
strftime
(
buf
,
sizeof
(
buf
),
timestamp_fmt
,
&
tm
);
#pragma GCC diagnostic pop
out
<<
buf
;
}
else
{
unsigned
int
secs
,
milli
;
unsigned
int
secs
,
milli
;
struct
timeval
tv
;
struct
timeval
tv
;
if
(
!
gettimeofday
(
&
tv
,
NULL
))
{
if
(
!
gettimeofday
(
&
tv
,
NULL
))
{
secs
=
tv
.
tv_sec
;
secs
=
tv
.
tv_sec
;
milli
=
tv
.
tv_usec
/
1000
;
// suppose that milli < 1000
milli
=
tv
.
tv_usec
/
1000
;
// suppose that milli < 1000
...
@@ -183,27 +156,11 @@ contextHeader(const char* const file, int line)
...
@@ -183,27 +156,11 @@ contextHeader(const char* const file, int line)
milli
=
0
;
milli
=
0
;
}
}
const
auto
prev_fill
=
out
.
fill
();
out
<<
secs
<<
'.'
<<
std
::
right
<<
std
::
setw
(
3
)
<<
std
::
setfill
(
'0'
)
<<
milli
<<
std
::
left
;
out
.
fill
(
prev_fill
);
}
out
<<
'|'
<<
std
::
right
<<
std
::
setw
(
5
)
<<
std
::
setfill
(
' '
)
<<
tid
<<
std
::
left
;
// Context
if
(
file
)
{
if
(
file
)
{
#ifdef RING_UWP
return
fmt
::
format
(
FMT_COMPILE
(
"[{: >3d}.{:0<3d}|{: >4}|{: <18s}:{: <4d}]"
),
secs
,
milli
,
tid
,
stripDirName
(
file
),
line
);
constexpr
auto
width
=
26
;
}
else
{
#else
return
fmt
::
format
(
FMT_COMPILE
(
"[{: >3d}.{:0<3d}|{: >4}]"
),
secs
,
milli
,
tid
);
constexpr
auto
width
=
18
;
#endif
out
<<
"|"
<<
std
::
setw
(
width
)
<<
stripDirName
(
file
)
<<
":"
<<
std
::
setw
(
5
)
<<
std
::
setfill
(
' '
)
<<
line
;
}
}
out
<<
"] "
;
return
out
.
str
();
}
}
struct
BufDeleter
struct
BufDeleter
...
...
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