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
e66ee8b7
Commit
e66ee8b7
authored
Jun 26, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix gcc and clang warnings
parent
a6e2f237
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
121 deletions
+77
-121
example/Makefile.clang
example/Makefile.clang
+3
-9
include/spdlog/details/fmt_helper.h
include/spdlog/details/fmt_helper.h
+17
-62
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+36
-33
include/spdlog/sinks/sink.h
include/spdlog/sinks/sink.h
+1
-1
include/spdlog/sinks/stdout_color_sinks.h
include/spdlog/sinks/stdout_color_sinks.h
+20
-16
No files found.
example/Makefile.clang
View file @
e66ee8b7
...
...
@@ -4,26 +4,20 @@ CXX_RELEASE_FLAGS = -O2
CXX_DEBUG_FLAGS
=
-g
all
:
example
bench
debug
:
example-debug
bench-debug
all
:
example
debug
:
example-debug
example
:
example.cpp
$(CXX)
example.cpp
-o
example-clang
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
bench
:
bench.cpp
$(CXX)
bench.cpp
-o
bench-clang
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
example-debug
:
example.cpp
$(CXX)
example.cpp
-o
example-clang-debug
$(CXXFLAGS)
$(CXX_DEBUG_FLAGS)
bench-debug
:
bench.cpp
$(CXX)
bench.cpp
-o
bench-clang-debug
$(CXXFLAGS)
$(CXX_DEBUG_FLAGS)
clean
:
rm
-f
*
.o logs/
*
.txt example-clang example-clang-debug
bench-clang bench-clang-debug
rm
-f
*
.o logs/
*
.txt example-clang example-clang-debug
rebuild
:
clean all
...
...
include/spdlog/details/fmt_helper.h
View file @
e66ee8b7
...
...
@@ -33,25 +33,30 @@ inline void append_int(T n, fmt::memory_buffer &dest)
dest
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
}
inline
void
append_and_pad2
(
int
n
,
fmt
::
memory_buffer
&
dest
)
inline
void
pad2
(
int
n
,
fmt
::
memory_buffer
&
dest
)
{
if
(
n
>
9
)
if
(
n
>
9
9
)
{
append_int
(
n
,
dest
);
return
;
}
if
(
n
>
9
)
// 10-99
{
dest
.
push_back
(
'0'
+
(
n
/
10
));
dest
.
push_back
(
'0'
+
(
n
%
10
));
return
;
}
if
(
n
>=
0
)
// 0-9
{
dest
.
push_back
(
'0'
);
append_int
(
n
,
dest
);
dest
.
push_back
(
'0'
+
n
);
return
;
}
// negatives (unlikely but just in case, let fmt deal with it)
// negatives (unlikely
,
but just in case, let fmt deal with it)
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
}
inline
void
append_and_
pad3
(
int
n
,
fmt
::
memory_buffer
&
dest
)
inline
void
pad3
(
int
n
,
fmt
::
memory_buffer
&
dest
)
{
if
(
n
>
99
)
{
...
...
@@ -59,71 +64,21 @@ inline void append_and_pad3(int n, fmt::memory_buffer &dest)
return
;
}
if
(
n
>
9
)
// 10-99
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
+
n
/
10
);
dest
.
push_back
(
'0'
+
n
%
10
);
return
;
}
else
if
(
n
>=
0
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
+
n
);
return
;
}
// negatives (unlikely, but just in case let fmt deal with it)
else
{
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
dest
.
push_back
(
'0'
+
n
/
10
);
dest
.
push_back
(
'0'
+
n
%
10
);
return
;
}
}
inline
void
append_and_pad6
(
int
n
,
fmt
::
memory_buffer
&
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
if
(
n
>=
0
)
if
(
n
>=
0
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
}
else
// negatives (unlikely, but just in case let fmt deal with it)
{
fmt
::
format_to
(
dest
,
"{:06}"
,
n
);
dest
.
push_back
(
'0'
+
n
);
return
;
}
append_int
(
n
,
dest
);
// negatives (unlikely, but just in case let fmt deal with it)
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
}
}
// namespace fmt_helper
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
e66ee8b7
...
...
@@ -121,11 +121,11 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt
::
format_to
(
dest
,
"{} {} {} "
,
days
[
tm_time
.
tm_wday
],
months
[
tm_time
.
tm_mon
],
tm_time
.
tm_mday
);
//
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_hour
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_hour
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_min
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_min
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_sec
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_sec
,
dest
);
dest
.
push_back
(
' '
);
fmt_helper
::
append_int
(
tm_time
.
tm_year
+
1900
,
dest
);
}
...
...
@@ -136,7 +136,7 @@ class C_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_year
%
100
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_year
%
100
,
dest
);
}
};
...
...
@@ -145,11 +145,11 @@ class D_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_mon
+
1
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_mon
+
1
,
dest
);
dest
.
push_back
(
'/'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_mday
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_mday
,
dest
);
dest
.
push_back
(
'/'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_year
%
100
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_year
%
100
,
dest
);
}
};
...
...
@@ -167,7 +167,7 @@ class m_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_mon
+
1
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_mon
+
1
,
dest
);
}
};
...
...
@@ -177,7 +177,7 @@ class d_formatter SPDLOG_FINAL : public flag_formatter
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
// fmt::format_to(dest, "{:02}", tm_time.tm_mday);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_mday
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_mday
,
dest
);
}
};
...
...
@@ -186,7 +186,7 @@ class H_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_hour
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_hour
,
dest
);
}
};
...
...
@@ -195,7 +195,7 @@ class I_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
to12h
(
tm_time
),
dest
);
fmt_helper
::
pad2
(
to12h
(
tm_time
),
dest
);
}
};
...
...
@@ -204,7 +204,7 @@ class M_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_min
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_min
,
dest
);
}
};
...
...
@@ -213,7 +213,7 @@ class S_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_sec
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_sec
,
dest
);
}
};
...
...
@@ -224,7 +224,7 @@ class e_formatter SPDLOG_FINAL : public flag_formatter
{
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
fmt_helper
::
append_and_
pad3
(
static_cast
<
int
>
(
millis
),
dest
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
dest
);
}
};
...
...
@@ -235,7 +235,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter
{
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
micros
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
duration
).
count
()
%
1000000
;
fmt
_helper
::
append_and_pad6
(
static_cast
<
int
>
(
micros
),
dest
);
fmt
::
format_to
(
dest
,
"{:06}"
,
static_cast
<
int
>
(
micros
)
);
}
};
...
...
@@ -275,11 +275,11 @@ class r_formatter SPDLOG_FINAL : public flag_formatter
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
// fmt::format_to(dest, "{:02}:{:02}:{:02} {}", to12h(tm_time), tm_time.tm_min, tm_time.tm_sec, ampm(tm_time));
fmt_helper
::
append_and_
pad2
(
to12h
(
tm_time
),
dest
);
fmt_helper
::
pad2
(
to12h
(
tm_time
),
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_min
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_min
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_sec
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_sec
,
dest
);
fmt
::
format_to
(
dest
,
" {}"
,
ampm
(
tm_time
));
}
};
...
...
@@ -289,9 +289,9 @@ class R_formatter SPDLOG_FINAL : public flag_formatter
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_hour
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_hour
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_min
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_min
,
dest
);
}
};
...
...
@@ -301,11 +301,11 @@ class T_formatter SPDLOG_FINAL : public flag_formatter
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
{
// fmt::format_to(dest, "{:02}:{:02}:{:02}", tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_hour
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_hour
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_min
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_min
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_sec
,
dest
);
fmt_helper
::
pad2
(
tm_time
.
tm_sec
,
dest
);
}
};
...
...
@@ -344,9 +344,9 @@ public:
int
h
=
total_minutes
/
60
;
int
m
=
total_minutes
%
60
;
dest
.
push_back
(
sign
);
fmt_helper
::
append_and_
pad2
(
h
,
dest
);
fmt_helper
::
pad2
(
h
,
dest
);
dest
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
m
,
dest
);
fmt_helper
::
pad2
(
m
,
dest
);
}
private:
...
...
@@ -466,24 +466,24 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
auto
seconds
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
duration
).
count
();
if
(
cached_header_
.
size
()
==
0
||
cached_seconds_ts_
!=
seconds
)
{
cached_header_
=
std
::
move
(
fmt
::
memory_buffer
()
);
cached_header_
=
fmt
::
memory_buffer
(
);
cached_header_
.
push_back
(
'['
);
fmt_helper
::
append_int
(
tm_time
.
tm_year
+
1900
,
cached_header_
);
cached_header_
.
push_back
(
'-'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_mon
+
1
,
cached_header_
);
fmt_helper
::
pad2
(
tm_time
.
tm_mon
+
1
,
cached_header_
);
cached_header_
.
push_back
(
'-'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_mday
,
cached_header_
);
fmt_helper
::
pad2
(
tm_time
.
tm_mday
,
cached_header_
);
cached_header_
.
push_back
(
' '
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_hour
,
cached_header_
);
fmt_helper
::
pad2
(
tm_time
.
tm_hour
,
cached_header_
);
cached_header_
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_min
,
cached_header_
);
fmt_helper
::
pad2
(
tm_time
.
tm_min
,
cached_header_
);
cached_header_
.
push_back
(
':'
);
fmt_helper
::
append_and_
pad2
(
tm_time
.
tm_sec
,
cached_header_
);
fmt_helper
::
pad2
(
tm_time
.
tm_sec
,
cached_header_
);
cached_header_
.
push_back
(
'.'
);
cached_seconds_ts_
=
seconds
;
...
...
@@ -491,7 +491,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
fmt_helper
::
append_buf
(
cached_header_
,
dest
);
auto
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
fmt_helper
::
append_and_
pad3
(
static_cast
<
int
>
(
millis
),
dest
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
dest
);
dest
.
push_back
(
']'
);
dest
.
push_back
(
' '
);
#else // no datetime needed
...
...
@@ -530,7 +530,9 @@ public:
std
::
string
eol
=
spdlog
::
details
::
os
::
default_eol
)
:
eol_
(
std
::
move
(
eol
))
,
pattern_time_
(
pattern_time
)
,
last_log_secs_
(
0
)
{
std
::
memset
(
&
cached_tm_
,
0
,
sizeof
(
cached_tm_
));
compile_pattern
(
pattern
);
}
...
...
@@ -557,7 +559,7 @@ public:
private:
const
std
::
string
eol_
;
const
pattern_time_type
pattern_time_
;
std
::
tm
cached_tm_
{}
;
std
::
tm
cached_tm_
;
std
::
chrono
::
seconds
last_log_secs_
;
std
::
vector
<
std
::
unique_ptr
<
details
::
flag_formatter
>>
formatters_
;
...
...
@@ -569,6 +571,7 @@ private:
}
return
details
::
os
::
gmtime
(
log_clock
::
to_time_t
(
msg
.
time
));
}
void
handle_flag
(
char
flag
)
{
switch
(
flag
)
...
...
include/spdlog/sinks/sink.h
View file @
e66ee8b7
...
...
@@ -48,7 +48,7 @@ public:
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
level_
.
load
(
std
::
memory_order_relaxed
));
}
void
set_pattern
(
const
std
::
string
&
pattern
)
void
set_pattern
(
const
std
::
string
&
pattern
)
{
formatter_
=
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
));
}
...
...
include/spdlog/sinks/stdout_color_sinks.h
View file @
e66ee8b7
...
...
@@ -27,23 +27,27 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
#endif
}
// namespace sinks
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_mt
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_mt
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_st
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_st
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_mt
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_mt
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_mt
>(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_mt
>(
logger_name
);
}
}
// namespace spdlog
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