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
c97c025a
Commit
c97c025a
authored
Aug 27, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang-format
parent
c55336e7
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
88 deletions
+82
-88
bench/async_bench.cpp
bench/async_bench.cpp
+1
-1
bench/latency.cpp
bench/latency.cpp
+1
-1
example/example.cpp
example/example.cpp
+1
-1
include/spdlog/async_logger-inl.h
include/spdlog/async_logger-inl.h
+0
-1
include/spdlog/async_logger.h
include/spdlog/async_logger.h
+0
-1
include/spdlog/details/backtracer.h
include/spdlog/details/backtracer.h
+5
-3
include/spdlog/details/log_msg_buffer.h
include/spdlog/details/log_msg_buffer.h
+1
-1
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+1
-1
include/spdlog/logger.h
include/spdlog/logger.h
+4
-5
tests/test_backtrace.cpp
tests/test_backtrace.cpp
+46
-51
tests/test_sink.h
tests/test_sink.h
+22
-22
No files found.
bench/async_bench.cpp
View file @
c97c025a
...
...
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
filename
,
true
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"async_logger"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
),
async_overflow_policy
::
block
);
bench_mt
(
howmany
,
std
::
move
(
logger
),
threads
);
//verify_file(filename, howmany);
//
verify_file(filename, howmany);
}
spdlog
::
info
(
""
);
...
...
bench/latency.cpp
View file @
c97c025a
...
...
@@ -160,7 +160,7 @@ int main(int argc, char *argv[])
benchmark
::
RegisterBenchmark
(
"async_logger"
,
bench_logger
,
async_logger
)
->
Threads
(
n_threads
)
->
UseRealTime
();
auto
async_logger_tracing
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"async_logger_tracing"
,
std
::
make_shared
<
null_sink_mt
>
(),
std
::
move
(
tp
),
spdlog
::
async_overflow_policy
::
overrun_oldest
);
"async_logger_tracing"
,
std
::
make_shared
<
null_sink_mt
>
(),
std
::
move
(
tp
),
spdlog
::
async_overflow_policy
::
overrun_oldest
);
async_logger_tracing
->
enable_backtrace
(
32
);
benchmark
::
RegisterBenchmark
(
"async_logger/tracing"
,
bench_logger
,
async_logger_tracing
)
->
Threads
(
n_threads
)
->
UseRealTime
();
...
...
example/example.cpp
View file @
c97c025a
...
...
@@ -45,7 +45,7 @@ int main(int, char *[])
// Loggers can store in a ring buffer all messages (including debug/trace) for later inspection.
// When needed, call dump_backtrace() to see what happened:
spdlog
::
enable_backtrace
(
10
);
// create ring buffer with capacity of 10 messages
for
(
int
i
=
0
;
i
<
100
;
i
++
)
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
spdlog
::
debug
(
"Backtrace message {}"
,
i
);
// not logged..
}
...
...
include/spdlog/async_logger-inl.h
View file @
c97c025a
...
...
@@ -83,4 +83,3 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
SPDLOG_LOGGER_CATCH
()
}
}
include/spdlog/async_logger.h
View file @
c97c025a
...
...
@@ -49,7 +49,6 @@ public:
async_logger
(
std
::
string
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
;
void
flush_
()
override
;
...
...
include/spdlog/details/backtracer.h
View file @
c97c025a
...
...
@@ -22,11 +22,13 @@ class backtracer
public:
explicit
backtracer
(
size_t
n_messages
)
:
n_messages_
{
n_messages
},
messages_
{
n_messages
}
:
n_messages_
{
n_messages
}
,
messages_
{
n_messages
}
{}
backtracer
(
const
backtracer
&
other
)
:
n_messages_
{
other
.
n_messages_
},
messages_
{
other
.
messages_
}
backtracer
(
const
backtracer
&
other
)
:
n_messages_
{
other
.
n_messages_
}
,
messages_
{
other
.
messages_
}
{}
size_t
n_messages
()
const
...
...
include/spdlog/details/log_msg_buffer.h
View file @
c97c025a
...
...
@@ -33,7 +33,7 @@ public:
}
log_msg_buffer
(
const
log_msg_buffer
&
other
)
:
log_msg
{
other
}
:
log_msg
{
other
}
{
buffer
.
append
(
logger_name
.
begin
(),
logger_name
.
end
());
buffer
.
append
(
payload
.
begin
(),
payload
.
end
());
...
...
include/spdlog/logger-inl.h
View file @
c97c025a
...
...
@@ -23,7 +23,7 @@ SPDLOG_INLINE logger::logger(const logger &other)
,
flush_level_
(
other
.
flush_level_
.
load
(
std
::
memory_order_relaxed
))
,
custom_err_handler_
(
other
.
custom_err_handler_
)
{
if
(
other
.
tracer_
)
if
(
other
.
tracer_
)
{
tracer_
=
std
::
make_shared
<
details
::
backtracer
>
(
*
other
.
tracer_
);
}
...
...
include/spdlog/logger.h
View file @
c97c025a
...
...
@@ -230,7 +230,7 @@ public:
#else
template
<
typename
...
Args
>
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
wstring_view_t
fmt
,
const
Args
&
...
args
)
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
wstring_view_t
fmt
,
const
Args
&
...
args
)
{
auto
level_enabled
=
should_log
(
lvl
);
if
(
!
level_enabled
&&
!
tracer_
)
...
...
@@ -239,14 +239,14 @@ public:
}
SPDLOG_TRY
{
// format to wmemory_buffer and convert to utf8
// format to wmemory_buffer and convert to utf8
fmt
::
wmemory_buffer
wbuf
;
fmt
::
format_to
(
wbuf
,
fmt
,
args
...);
fmt
::
memory_buffer
buf
;
details
::
os
::
wstr_to_utf8buf
(
wstring_view_t
(
wbuf
.
data
(),
wbuf
.
size
()),
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
if
(
level_enabled
)
{
sink_it_
(
log_msg
);
...
...
@@ -258,7 +258,7 @@ public:
}
SPDLOG_LOGGER_CATCH
()
}
template
<
typename
...
Args
>
void
log
(
level
::
level_enum
lvl
,
wstring_view_t
fmt
,
const
Args
&
...
args
)
{
...
...
@@ -356,7 +356,6 @@ public:
// error handler
void
set_error_handler
(
err_handler
);
protected:
std
::
string
name_
;
std
::
vector
<
sink_ptr
>
sinks_
;
...
...
tests/test_backtrace.cpp
View file @
c97c025a
...
...
@@ -2,69 +2,64 @@
#include "test_sink.h"
#include "spdlog/async.h"
TEST_CASE
(
"bactrace1"
,
"[bactrace]"
)
{
using
spdlog
::
sinks
::
test_sink_st
;
auto
test_sink
=
std
::
make_shared
<
test_sink_st
>
();
int
backtrace_size
=
5
;
using
spdlog
::
sinks
::
test_sink_st
;
auto
test_sink
=
std
::
make_shared
<
test_sink_st
>
();
int
backtrace_size
=
5
;
spdlog
::
logger
logger
(
"test-backtrace"
,
test_sink
);
logger
.
set_pattern
(
"%v"
);
logger
.
enable_backtrace
(
backtrace_size
);
spdlog
::
logger
logger
(
"test-backtrace"
,
test_sink
);
logger
.
set_pattern
(
"%v"
);
logger
.
enable_backtrace
(
backtrace_size
);
logger
.
info
(
"info message"
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
logger
.
debug
(
"debug message {}"
,
i
);
REQUIRE
(
test_sink
->
lines
().
size
()
==
1
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"info message"
);
logger
.
info
(
"info message"
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
logger
.
debug
(
"debug message {}"
,
i
);
logger
.
dump_backtrace
();
REQUIRE
(
test_sink
->
lines
().
size
()
==
backtrace_size
+
3
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"****************** Backtrace Start ******************"
);
REQUIRE
(
test_sink
->
lines
()[
2
]
==
"debug message 95"
);
REQUIRE
(
test_sink
->
lines
()[
3
]
==
"debug message 96"
);
REQUIRE
(
test_sink
->
lines
()[
4
]
==
"debug message 97"
);
REQUIRE
(
test_sink
->
lines
()[
5
]
==
"debug message 98"
);
REQUIRE
(
test_sink
->
lines
()[
6
]
==
"debug message 99"
);
REQUIRE
(
test_sink
->
lines
()[
7
]
==
"****************** Backtrace End ********************"
);
}
REQUIRE
(
test_sink
->
lines
().
size
()
==
1
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"info message"
);
logger
.
dump_backtrace
();
REQUIRE
(
test_sink
->
lines
().
size
()
==
backtrace_size
+
3
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"****************** Backtrace Start ******************"
);
REQUIRE
(
test_sink
->
lines
()[
2
]
==
"debug message 95"
);
REQUIRE
(
test_sink
->
lines
()[
3
]
==
"debug message 96"
);
REQUIRE
(
test_sink
->
lines
()[
4
]
==
"debug message 97"
);
REQUIRE
(
test_sink
->
lines
()[
5
]
==
"debug message 98"
);
REQUIRE
(
test_sink
->
lines
()[
6
]
==
"debug message 99"
);
REQUIRE
(
test_sink
->
lines
()[
7
]
==
"****************** Backtrace End ********************"
);
}
TEST_CASE
(
"bactrace-async"
,
"[bactrace]"
)
{
using
spdlog
::
sinks
::
test_sink_mt
;
auto
test_sink
=
std
::
make_shared
<
test_sink_mt
>
();
using
spdlog
::
details
::
os
::
sleep_for_millis
;
using
spdlog
::
sinks
::
test_sink_mt
;
auto
test_sink
=
std
::
make_shared
<
test_sink_mt
>
();
using
spdlog
::
details
::
os
::
sleep_for_millis
;
int
backtrace_size
=
5
;
int
backtrace_size
=
5
;
spdlog
::
init_thread_pool
(
120
,
1
);
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"test-bactrace-async"
,
test_sink
,
spdlog
::
thread_pool
());
logger
->
set_pattern
(
"%v"
);
logger
->
enable_backtrace
(
backtrace_size
);
spdlog
::
init_thread_pool
(
120
,
1
);
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"test-bactrace-async"
,
test_sink
,
spdlog
::
thread_pool
());
logger
->
set_pattern
(
"%v"
);
logger
->
enable_backtrace
(
backtrace_size
);
logger
->
info
(
"info message"
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
logger
->
debug
(
"debug message {}"
,
i
);
sleep_for_millis
(
10
);
REQUIRE
(
test_sink
->
lines
().
size
()
==
1
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"info message"
);
logger
->
info
(
"info message"
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
logger
->
debug
(
"debug message {}"
,
i
);
logger
->
dump_backtrace
();
sleep_for_millis
(
100
);
// give time for the async dump to complete
REQUIRE
(
test_sink
->
lines
().
size
()
==
backtrace_size
+
3
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"****************** Backtrace Start ******************"
);
REQUIRE
(
test_sink
->
lines
()[
2
]
==
"debug message 95"
);
REQUIRE
(
test_sink
->
lines
()[
3
]
==
"debug message 96"
);
REQUIRE
(
test_sink
->
lines
()[
4
]
==
"debug message 97"
);
REQUIRE
(
test_sink
->
lines
()[
5
]
==
"debug message 98"
);
REQUIRE
(
test_sink
->
lines
()[
6
]
==
"debug message 99"
);
REQUIRE
(
test_sink
->
lines
()[
7
]
==
"****************** Backtrace End ********************"
);
}
sleep_for_millis
(
10
);
REQUIRE
(
test_sink
->
lines
().
size
()
==
1
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"info message"
);
logger
->
dump_backtrace
();
sleep_for_millis
(
100
);
// give time for the async dump to complete
REQUIRE
(
test_sink
->
lines
().
size
()
==
backtrace_size
+
3
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"****************** Backtrace Start ******************"
);
REQUIRE
(
test_sink
->
lines
()[
2
]
==
"debug message 95"
);
REQUIRE
(
test_sink
->
lines
()[
3
]
==
"debug message 96"
);
REQUIRE
(
test_sink
->
lines
()[
4
]
==
"debug message 97"
);
REQUIRE
(
test_sink
->
lines
()[
5
]
==
"debug message 98"
);
REQUIRE
(
test_sink
->
lines
()[
6
]
==
"debug message 99"
);
REQUIRE
(
test_sink
->
lines
()[
7
]
==
"****************** Backtrace End ********************"
);
}
tests/test_sink.h
View file @
c97c025a
...
...
@@ -18,7 +18,8 @@ namespace sinks {
template
<
class
Mutex
>
class
test_sink
:
public
base_sink
<
Mutex
>
{
const
size_t
lines_to_save
=
100
;
const
size_t
lines_to_save
=
100
;
public:
size_t
msg_counter
()
{
...
...
@@ -34,42 +35,41 @@ public:
void
set_delay
(
std
::
chrono
::
milliseconds
delay
)
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
delay_
=
delay
;
}
// return last output without the eol
std
::
vector
<
std
::
string
>
lines
()
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
return
lines_
;
}
// return last output without the eol
std
::
vector
<
std
::
string
>
lines
()
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
return
lines_
;
}
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
fmt
::
memory_buffer
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
// save the line without the eol
auto
eol_len
=
strlen
(
details
::
os
::
default_eol
);
if
(
lines_
.
size
()
<
lines_to_save
)
{
lines_
.
emplace_back
(
formatted
.
begin
(),
formatted
.
end
()
-
eol_len
);
}
msg_counter_
++
;
std
::
this_thread
::
sleep_for
(
delay_
);
{
fmt
::
memory_buffer
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
// save the line without the eol
auto
eol_len
=
strlen
(
details
::
os
::
default_eol
);
if
(
lines_
.
size
()
<
lines_to_save
)
{
lines_
.
emplace_back
(
formatted
.
begin
(),
formatted
.
end
()
-
eol_len
);
}
msg_counter_
++
;
std
::
this_thread
::
sleep_for
(
delay_
);
}
void
flush_
()
override
{
flush_counter_
++
;
}
size_t
msg_counter_
{
0
};
size_t
flush_counter_
{
0
};
std
::
chrono
::
milliseconds
delay_
{
std
::
chrono
::
milliseconds
::
zero
()};
std
::
vector
<
std
::
string
>
lines_
;
std
::
vector
<
std
::
string
>
lines_
;
};
using
test_sink_mt
=
test_sink
<
std
::
mutex
>
;
...
...
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