Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
0d7a1d1e
Commit
0d7a1d1e
authored
May 26, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
80f19d71
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
35 additions
and
34 deletions
+35
-34
spdlog-async.cpp
bench/spdlog-async.cpp
+1
-1
spdlog-bench-mt.cpp
bench/spdlog-bench-mt.cpp
+1
-1
spdlog-bench.cpp
bench/spdlog-bench.cpp
+1
-1
example.cpp
example/example.cpp
+3
-4
common.h
include/spdlog/common.h
+9
-3
async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+0
-0
logger_impl.h
include/spdlog/details/logger_impl.h
+0
-0
thread_pool.h
include/spdlog/details/thread_pool.h
+17
-19
errors.cpp
tests/errors.cpp
+0
-0
file_log.cpp
tests/file_log.cpp
+0
-0
test_async.cpp
tests/test_async.cpp
+3
-5
No files found.
bench/spdlog-async.cpp
View file @
0d7a1d1e
...
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
...
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
thread_count
=
std
::
atoi
(
argv
[
1
]);
thread_count
=
std
::
atoi
(
argv
[
1
]);
int
howmany
=
1000000
;
int
howmany
=
1000000
;
spdlog
::
init_thread_pool
(
howmany
,
1
);
spdlog
::
init_thread_pool
(
howmany
,
1
);
auto
logger
=
spdlog
::
create_async_logger
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"file_logger"
,
"logs/spdlog-bench-async.log"
,
false
);
auto
logger
=
spdlog
::
create_async_logger
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"file_logger"
,
"logs/spdlog-bench-async.log"
,
false
);
logger
->
set_pattern
(
"[%Y-%m-%d %T.%F]: %L %t %v"
);
logger
->
set_pattern
(
"[%Y-%m-%d %T.%F]: %L %t %v"
);
...
...
bench/spdlog-bench-mt.cpp
View file @
0d7a1d1e
...
@@ -10,8 +10,8 @@
...
@@ -10,8 +10,8 @@
#include <thread>
#include <thread>
#include <vector>
#include <vector>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/simple_file_sink.h"
#include "spdlog/sinks/simple_file_sink.h"
#include "spdlog/spdlog.h"
using
namespace
std
;
using
namespace
std
;
...
...
bench/spdlog-bench.cpp
View file @
0d7a1d1e
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
#include <chrono>
#include <chrono>
#include <iostream>
#include <iostream>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/simple_file_sink.h"
#include "spdlog/sinks/simple_file_sink.h"
#include "spdlog/spdlog.h"
int
main
(
int
,
char
*
[])
int
main
(
int
,
char
*
[])
{
{
...
...
example/example.cpp
View file @
0d7a1d1e
...
@@ -82,7 +82,7 @@ int main(int, char *[])
...
@@ -82,7 +82,7 @@ int main(int, char *[])
// Asynchronous logging is very fast..
// Asynchronous logging is very fast..
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
//async_example();
//
async_example();
// Log user-defined types example
// Log user-defined types example
user_defined_example
();
user_defined_example
();
...
@@ -107,7 +107,7 @@ int main(int, char *[])
...
@@ -107,7 +107,7 @@ int main(int, char *[])
#include "spdlog/async.h"
#include "spdlog/async.h"
void
async_example
()
void
async_example
()
{
{
//auto async_file = spd::basic_logger_mt<spdlog::create_async>("async_file_logger", "logs/async_log.txt");
//
auto async_file = spd::basic_logger_mt<spdlog::create_async>("async_file_logger", "logs/async_log.txt");
for
(
int
j
=
0
;
j
<
1
;
j
++
)
for
(
int
j
=
0
;
j
<
1
;
j
++
)
{
{
...
@@ -119,8 +119,7 @@ void async_example()
...
@@ -119,8 +119,7 @@ void async_example()
}
}
spdlog
::
drop_all
();
spdlog
::
drop_all
();
}
}
//std::this_thread::sleep_for(std::chrono::seconds(1));
// std::this_thread::sleep_for(std::chrono::seconds(1));
// you can also modify thread pool settings *before* creating the logger:
// you can also modify thread pool settings *before* creating the logger:
// spdlog::init_thread_pool(32768, 4); // queue with max 32k items 4 backing threads.
// spdlog::init_thread_pool(32768, 4); // queue with max 32k items 4 backing threads.
...
...
include/spdlog/common.h
View file @
0d7a1d1e
...
@@ -179,7 +179,13 @@ using filename_t = std::wstring;
...
@@ -179,7 +179,13 @@ using filename_t = std::wstring;
using
filename_t
=
std
::
string
;
using
filename_t
=
std
::
string
;
#endif
#endif
#define SPDLOG_CATCH_AND_HANDLE \
#define SPDLOG_CATCH_AND_HANDLE catch (const std::exception &ex) {_err_handler(ex.what());}\
catch (const std::exception &ex) \
catch (...) {_err_handler("Unknown exeption in logger");}
{ \
_err_handler(ex.what()); \
} \
catch (...) \
{ \
_err_handler("Unknown exeption in logger"); \
}
}
// namespace spdlog
}
// namespace spdlog
include/spdlog/details/async_logger_impl.h
View file @
0d7a1d1e
include/spdlog/details/logger_impl.h
View file @
0d7a1d1e
include/spdlog/details/thread_pool.h
View file @
0d7a1d1e
...
@@ -10,21 +10,21 @@
...
@@ -10,21 +10,21 @@
#include <vector>
#include <vector>
namespace
spdlog
{
namespace
spdlog
{
namespace
details
{
namespace
details
{
using
async_logger_ptr
=
std
::
shared_ptr
<
spdlog
::
async_logger
>
;
using
async_logger_ptr
=
std
::
shared_ptr
<
spdlog
::
async_logger
>
;
enum
class
async_msg_type
enum
class
async_msg_type
{
{
log
,
log
,
flush
,
flush
,
terminate
terminate
};
};
// Async msg to move to/from the queue
// Async msg to move to/from the queue
// Movable only. should never be copied
// Movable only. should never be copied
struct
async_msg
struct
async_msg
{
{
async_msg_type
msg_type
;
async_msg_type
msg_type
;
level
::
level_enum
level
;
level
::
level_enum
level
;
log_clock
::
time_point
time
;
log_clock
::
time_point
time
;
...
@@ -78,11 +78,11 @@ namespace spdlog {
...
@@ -78,11 +78,11 @@ namespace spdlog {
msg
.
color_range_start
=
0
;
msg
.
color_range_start
=
0
;
msg
.
color_range_end
=
0
;
msg
.
color_range_end
=
0
;
}
}
};
};
class
thread_pool
class
thread_pool
{
{
public
:
public
:
using
item_type
=
async_msg
;
using
item_type
=
async_msg
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
using
clock_type
=
std
::
chrono
::
steady_clock
;
using
clock_type
=
std
::
chrono
::
steady_clock
;
...
@@ -139,7 +139,7 @@ namespace spdlog {
...
@@ -139,7 +139,7 @@ namespace spdlog {
return
msg_counter_
.
load
(
std
::
memory_order_relaxed
);
return
msg_counter_
.
load
(
std
::
memory_order_relaxed
);
}
}
private
:
private
:
std
::
atomic
<
size_t
>
msg_counter_
;
// total # of messages processed in this pool
std
::
atomic
<
size_t
>
msg_counter_
;
// total # of messages processed in this pool
q_type
_q
;
q_type
_q
;
...
@@ -159,9 +159,7 @@ namespace spdlog {
...
@@ -159,9 +159,7 @@ namespace spdlog {
void
worker_loop
()
void
worker_loop
()
{
{
while
(
process_next_msg
())
while
(
process_next_msg
())
{};
{
};
}
}
// process next message in the queue
// process next message in the queue
...
@@ -200,7 +198,7 @@ namespace spdlog {
...
@@ -200,7 +198,7 @@ namespace spdlog {
assert
(
false
);
assert
(
false
);
return
true
;
// should not be reached
return
true
;
// should not be reached
}
}
};
};
}
// namespace details
}
// namespace details
}
// namespace spdlog
}
// namespace spdlog
tests/errors.cpp
View file @
0d7a1d1e
tests/file_log.cpp
View file @
0d7a1d1e
tests/test_async.cpp
View file @
0d7a1d1e
#include "includes.h"
#include "includes.h"
#include "test_sink.h"
#include "spdlog/async.h"
#include "spdlog/async.h"
#include "spdlog/sinks/simple_file_sink.h"
#include "spdlog/sinks/simple_file_sink.h"
#include "test_sink.h"
//std::unique_ptr<spdlog::async_logger> create_logger(size_t tp_queue_size, size_t tp_threads)
//
std::unique_ptr<spdlog::async_logger> create_logger(size_t tp_queue_size, size_t tp_threads)
//{
//{
// auto tp = std::make_shared<details::thread_pool>(8192, 1);
// auto tp = std::make_shared<details::thread_pool>(8192, 1);
// auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block_retry);
// auto logger = std::make_shared<async_logger>("as", test_sink, tp, async_overflow_policy::block_retry);
...
@@ -87,7 +87,6 @@ TEST_CASE("multi threads", "[async]")
...
@@ -87,7 +87,6 @@ TEST_CASE("multi threads", "[async]")
{
{
logger
->
info
(
"Hello message #{}"
,
j
);
logger
->
info
(
"Hello message #{}"
,
j
);
}
}
});
});
}
}
...
@@ -96,7 +95,6 @@ TEST_CASE("multi threads", "[async]")
...
@@ -96,7 +95,6 @@ TEST_CASE("multi threads", "[async]")
t
.
join
();
t
.
join
();
}
}
logger
->
flush
();
logger
->
flush
();
}
}
REQUIRE
(
test_sink
->
msg_counter
()
==
messages
*
n_threads
);
REQUIRE
(
test_sink
->
msg_counter
()
==
messages
*
n_threads
);
...
@@ -110,7 +108,7 @@ TEST_CASE("to_file", "[async]")
...
@@ -110,7 +108,7 @@ TEST_CASE("to_file", "[async]")
size_t
messages
=
512
;
size_t
messages
=
512
;
size_t
n_threads
=
4
;
size_t
n_threads
=
4
;
spdlog
::
init_thread_pool
(
queue_size
,
n_threads
);
spdlog
::
init_thread_pool
(
queue_size
,
n_threads
);
auto
logger
=
spdlog
::
basic_logger_mt
<
spdlog
::
create_async
>
(
"as"
,
"logs/async_test.log"
,
true
);
auto
logger
=
spdlog
::
basic_logger_mt
<
spdlog
::
create_async
>
(
"as"
,
"logs/async_test.log"
,
true
);
std
::
vector
<
std
::
thread
>
threads
;
std
::
vector
<
std
::
thread
>
threads
;
for
(
size_t
i
=
0
;
i
<
n_threads
;
i
++
)
for
(
size_t
i
=
0
;
i
<
n_threads
;
i
++
)
...
...
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