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
16ee72da
Commit
16ee72da
authored
Jul 10, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang format
parent
d409e536
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
207 additions
and
211 deletions
+207
-211
bench/bench.cpp
bench/bench.cpp
+2
-3
bench/latency.cpp
bench/latency.cpp
+6
-10
include/spdlog/details/fmt_helper.h
include/spdlog/details/fmt_helper.h
+5
-5
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+17
-17
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+4
-4
include/spdlog/details/thread_pool.h
include/spdlog/details/thread_pool.h
+161
-161
include/spdlog/logger.h
include/spdlog/logger.h
+3
-3
include/spdlog/sinks/rotating_file_sink.h
include/spdlog/sinks/rotating_file_sink.h
+9
-8
No files found.
bench/bench.cpp
View file @
16ee72da
...
...
@@ -32,7 +32,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
int
main
(
int
argc
,
char
*
argv
[])
{
int
howmany
=
1000000
;
int
queue_size
=
howmany
+
2
;
int
threads
=
10
;
...
...
@@ -76,7 +75,7 @@ int main(int argc, char *argv[])
auto
daily_mt
=
spdlog
::
daily_logger_mt
(
"daily_mt"
,
"logs/daily_mt.log"
);
bench_mt
(
howmany
,
daily_mt
,
threads
);
bench_mt
(
howmany
,
spdlog
::
create
<
null_sink_mt
>
(
"null_mt"
),
threads
);
bench_mt
(
howmany
,
spdlog
::
create
<
null_sink_mt
>
(
"null_mt"
),
threads
);
cout
<<
"
\n
*******************************************************************************
\n
"
;
cout
<<
"async logging.. "
<<
threads
<<
" threads sharing same logger, "
<<
format
(
howmany
)
<<
" iterations "
<<
endl
;
...
...
@@ -112,7 +111,7 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
auto
delta
=
high_resolution_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout
<<
"Elapsed: "
<<
delta_d
<<
"
\t
"
<<
format
(
int
(
howmany
/
delta_d
))
<<
"/sec"
<<
endl
;
spdlog
::
drop
(
log
->
name
());
spdlog
::
drop
(
log
->
name
());
}
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
)
...
...
bench/latency.cpp
View file @
16ee72da
...
...
@@ -29,9 +29,9 @@ using namespace utils;
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
);
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
);
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
std
::
srand
(
static_cast
<
unsigned
>
(
std
::
time
(
nullptr
)));
// use current time as seed for random generator
std
::
srand
(
static_cast
<
unsigned
>
(
std
::
time
(
nullptr
)));
// use current time as seed for random generator
int
howmany
=
1000000
;
int
queue_size
=
howmany
+
2
;
int
threads
=
10
;
...
...
@@ -91,7 +91,6 @@ int main(int , char *[])
return
EXIT_SUCCESS
;
}
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
{
using
namespace
std
::
chrono
;
...
...
@@ -106,10 +105,10 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
auto
start
=
high_resolution_clock
::
now
();
log
->
info
(
"Hello logger: msg number {}"
,
i
);
auto
delta_nanos
=
chrono
::
duration_cast
<
nanoseconds
>
(
high_resolution_clock
::
now
()
-
start
);
total_nanos
+=
delta_nanos
;
total_nanos
+=
delta_nanos
;
}
auto
avg
=
total_nanos
.
count
()
/
howmany
;
auto
avg
=
total_nanos
.
count
()
/
howmany
;
cout
<<
format
(
avg
)
<<
" ns/call"
<<
endl
;
}
...
...
@@ -131,7 +130,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
auto
start
=
high_resolution_clock
::
now
();
log
->
info
(
"Hello logger: msg number {}"
,
j
);
auto
delta_nanos
=
chrono
::
duration_cast
<
nanoseconds
>
(
high_resolution_clock
::
now
()
-
start
);
total_nanos
+=
delta_nanos
.
count
();
total_nanos
+=
delta_nanos
.
count
();
}
}));
}
...
...
@@ -141,9 +140,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
t
.
join
();
};
auto
avg
=
total_nanos
/
howmany
;
auto
avg
=
total_nanos
/
howmany
;
cout
<<
format
(
avg
)
<<
" ns/call"
<<
endl
;
}
include/spdlog/details/fmt_helper.h
View file @
16ee72da
...
...
@@ -9,14 +9,14 @@ namespace spdlog {
namespace
details
{
namespace
fmt_helper
{
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
append_str
(
const
std
::
string
&
str
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
auto
*
str_ptr
=
str
.
data
();
dest
.
append
(
str_ptr
,
str_ptr
+
str
.
size
());
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
append_c_str
(
const
char
*
c_str
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
char
ch
;
...
...
@@ -41,7 +41,7 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
dest
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
pad2
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99
)
...
...
@@ -65,7 +65,7 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
}
template
<
size_t
Buffer_Size
>
template
<
size_t
Buffer_Size
>
inline
void
pad3
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99
)
...
...
@@ -91,7 +91,7 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
}
template
<
size_t
Buffer_Size
>
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
...
...
include/spdlog/details/logger_impl.h
View file @
16ee72da
...
...
@@ -175,23 +175,23 @@ inline void spdlog::logger::critical(const T &msg)
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template
<
typename
...
Args
>
inline
void
spdlog
::
logger
::
log
(
level
::
level_enum
lvl
,
const
wchar_t
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
return
;
}
decltype
(
wstring_converter_
)
::
byte_string
utf8_string
;
try
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
wstring_converter_mutex_
);
utf8_string
=
wstring_converter_
.
to_bytes
(
fmt
);
}
log
(
lvl
,
utf8_string
.
c_str
(),
args
...);
}
SPDLOG_CATCH_AND_HANDLE
{
if
(
!
should_log
(
lvl
))
{
return
;
}
decltype
(
wstring_converter_
)
::
byte_string
utf8_string
;
try
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
wstring_converter_mutex_
);
utf8_string
=
wstring_converter_
.
to_bytes
(
fmt
);
}
log
(
lvl
,
utf8_string
.
c_str
(),
args
...);
}
SPDLOG_CATCH_AND_HANDLE
}
template
<
typename
...
Args
>
...
...
include/spdlog/details/pattern_formatter.h
View file @
16ee72da
...
...
@@ -120,7 +120,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::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
//
fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
// date
fmt_helper
::
append_str
(
days
[
tm_time
.
tm_wday
],
dest
);
dest
.
push_back
(
' '
);
...
...
@@ -496,7 +496,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
// 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
)
if
(
millis
!=
millis_cache_timestamp_
||
cached_millis_
.
size
()
==
0
)
{
cached_millis_
.
resize
(
0
);
fmt_helper
::
pad3
(
static_cast
<
int
>
(
millis
),
cached_millis_
);
...
...
@@ -528,8 +528,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
}
private:
std
::
chrono
::
seconds
cache_timestamp_
{
0
};
std
::
chrono
::
milliseconds
::
rep
millis_cache_timestamp_
{
0
};
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_
;
};
...
...
include/spdlog/details/thread_pool.h
View file @
16ee72da
This diff is collapsed.
Click to expand it.
include/spdlog/logger.h
View file @
16ee72da
...
...
@@ -63,7 +63,7 @@ public:
template
<
typename
...
Args
>
void
critical
(
const
char
*
fmt
,
const
Args
&
...
args
);
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template
<
typename
...
Args
>
void
log
(
level
::
level_enum
lvl
,
const
wchar_t
*
fmt
,
const
Args
&
...
args
);
...
...
@@ -151,8 +151,8 @@ protected:
std
::
atomic
<
size_t
>
msg_counter_
;
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
std
::
wstring_convert
<
std
::
codecvt_utf8
<
wchar_t
>>
wstring_converter_
;
std
::
mutex
wstring_converter_mutex_
;
std
::
wstring_convert
<
std
::
codecvt_utf8
<
wchar_t
>>
wstring_converter_
;
std
::
mutex
wstring_converter_mutex_
;
#endif
};
}
// namespace spdlog
...
...
include/spdlog/sinks/rotating_file_sink.h
View file @
16ee72da
...
...
@@ -95,14 +95,15 @@ private:
}
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
details
::
os
::
rename
(
src
,
target
)
!=
0
)
{
// if failed try again after small delay.
// this is a workaround to a windows issue, where very high rotation rates sometimes fail (because of antivirus?).
details
::
os
::
sleep_for_millis
(
20
);
details
::
os
::
remove
(
target
);
if
(
details
::
os
::
rename
(
src
,
target
)
!=
0
)
{
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
),
errno
);
}
// if failed try again after small delay.
// this is a workaround to a windows issue, where very high rotation rates sometimes fail (because of antivirus?).
details
::
os
::
sleep_for_millis
(
20
);
details
::
os
::
remove
(
target
);
if
(
details
::
os
::
rename
(
src
,
target
)
!=
0
)
{
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
),
errno
);
}
}
}
file_helper_
.
reopen
(
true
);
...
...
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