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
cd4dcbab
Commit
cd4dcbab
authored
Jul 07, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed simple_file_sink -> basic_file_sink
parent
69c11ea7
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
54 additions
and
61 deletions
+54
-61
bench.cpp
bench/bench.cpp
+2
-2
spdlog-async.cpp
bench/spdlog-async.cpp
+2
-2
example.cpp
example/example.cpp
+10
-4
multisink.cpp
example/multisink.cpp
+2
-2
async.h
include/spdlog/async.h
+3
-3
base_sink.h
include/spdlog/sinks/base_sink.h
+2
-12
basic_file_sink.h
include/spdlog/sinks/basic_file_sink.h
+6
-6
sink.h
include/spdlog/sinks/sink.h
+13
-15
spdlog.h
include/spdlog/spdlog.h
+2
-2
errors.cpp
tests/errors.cpp
+4
-4
file_log.cpp
tests/file_log.cpp
+2
-2
includes.h
tests/includes.h
+1
-1
test_async.cpp
tests/test_async.cpp
+3
-3
test_macros.cpp
tests/test_macros.cpp
+2
-3
No files found.
bench/bench.cpp
View file @
cd4dcbab
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/null_sink.h"
#include "spdlog/sinks/null_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/
simple
_file_sink.h"
#include "spdlog/sinks/
basic
_file_sink.h"
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
#include "utils.h"
#include "utils.h"
#include <atomic>
#include <atomic>
...
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
...
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
for
(
int
i
=
0
;
i
<
3
;
++
i
)
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
{
spdlog
::
init_thread_pool
(
queue_size
,
1
);
spdlog
::
init_thread_pool
(
queue_size
,
1
);
auto
as
=
spdlog
::
basic_logger_mt
<
spdlog
::
create_async
>
(
"as"
,
"logs/basic_async.log"
,
true
);
auto
as
=
spdlog
::
basic_logger_mt
<
spdlog
::
async_factory
>
(
"as"
,
"logs/basic_async.log"
,
true
);
bench_mt
(
howmany
,
as
,
threads
);
bench_mt
(
howmany
,
as
,
threads
);
spdlog
::
drop
(
"as"
);
spdlog
::
drop
(
"as"
);
}
}
...
...
bench/spdlog-async.cpp
View file @
cd4dcbab
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include <vector>
#include <vector>
#include "spdlog/async.h"
#include "spdlog/async.h"
#include "spdlog/sinks/
simple
_file_sink.h"
#include "spdlog/sinks/
basic
_file_sink.h"
using
namespace
std
;
using
namespace
std
;
...
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
...
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
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
::
basic
_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"
);
std
::
cout
<<
"To stop, press <Enter>"
<<
std
::
endl
;
std
::
cout
<<
"To stop, press <Enter>"
<<
std
::
endl
;
...
...
example/example.cpp
View file @
cd4dcbab
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/
simple
_file_sink.h"
#include "spdlog/sinks/
basic
_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include <iostream>
#include <iostream>
...
@@ -29,6 +29,7 @@ int main(int, char *[])
...
@@ -29,6 +29,7 @@ int main(int, char *[])
try
try
{
{
spd
::
set_pattern
(
"TEST PATTERN %v"
);
auto
console
=
spdlog
::
stdout_color_st
(
"console"
);
auto
console
=
spdlog
::
stdout_color_st
(
"console"
);
console
->
info
(
"Welcome to spdlog!"
);
console
->
info
(
"Welcome to spdlog!"
);
...
@@ -107,10 +108,15 @@ int main(int, char *[])
...
@@ -107,10 +108,15 @@ 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"
);
// default thread pool settings can be modified *before* creating the async logger:
// spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread.
// thread pool settings can be modified *before* creating the async 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.
auto
async_file
=
spd
::
basic_logger_mt
<
spdlog
::
async_factory
>
(
"async_file_logger"
,
"logs/async_log.txt"
);
// alternatively:
// auto async_file = spd::create_async<spd::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");
for
(
int
i
=
0
;
i
<
100
;
++
i
)
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
{
async_file
->
info
(
"Async message #{}"
,
i
+
1
);
async_file
->
info
(
"Async message #{}"
,
i
+
1
);
...
...
example/multisink.cpp
View file @
cd4dcbab
...
@@ -15,8 +15,8 @@ int main(int, char *[])
...
@@ -15,8 +15,8 @@ int main(int, char *[])
// Each sink can have it's own log level and a message will be logged.
// Each sink can have it's own log level and a message will be logged.
std
::
vector
<
spdlog
::
sink_ptr
>
sinks
;
std
::
vector
<
spdlog
::
sink_ptr
>
sinks
;
sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
stdout_sink_mt
>
());
sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
stdout_sink_mt
>
());
sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"./log_regular_file.txt"
));
sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"./log_regular_file.txt"
));
sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"./log_debug_file.txt"
));
sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"./log_debug_file.txt"
));
spdlog
::
logger
console_multisink
(
"multisink"
,
sinks
.
begin
(),
sinks
.
end
());
spdlog
::
logger
console_multisink
(
"multisink"
,
sinks
.
begin
(),
sinks
.
end
());
console_multisink
.
set_level
(
spdlog
::
level
::
warn
);
console_multisink
.
set_level
(
spdlog
::
level
::
warn
);
...
...
include/spdlog/async.h
View file @
cd4dcbab
...
@@ -23,7 +23,7 @@ namespace spdlog {
...
@@ -23,7 +23,7 @@ namespace spdlog {
// async logger factory - creates async loggers backed with thread pool.
// async logger factory - creates async loggers backed with thread pool.
// if a global thread pool doesn't already exist, create it with default queue size of 8192 items and single thread.
// if a global thread pool doesn't already exist, create it with default queue size of 8192 items and single thread.
struct
create_async
struct
async_factory
{
{
template
<
typename
Sink
,
typename
...
SinkArgs
>
template
<
typename
Sink
,
typename
...
SinkArgs
>
static
std
::
shared_ptr
<
async_logger
>
create
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
args
)
static
std
::
shared_ptr
<
async_logger
>
create
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
args
)
...
@@ -46,9 +46,9 @@ struct create_async
...
@@ -46,9 +46,9 @@ struct create_async
};
};
template
<
typename
Sink
,
typename
...
SinkArgs
>
template
<
typename
Sink
,
typename
...
SinkArgs
>
inline
std
::
shared_ptr
<
spdlog
::
logger
>
create_async
_logger
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
sink_args
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
create_async
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
sink_args
)
{
{
return
create_async
::
create
<
Sink
>
(
logger_name
,
std
::
forward
<
SinkArgs
>
(
sink_args
)...);
return
async_factory
::
create
<
Sink
>
(
logger_name
,
std
::
forward
<
SinkArgs
>
(
sink_args
)...);
}
}
// set global thread pool.
// set global thread pool.
...
...
include/spdlog/sinks/base_sink.h
View file @
cd4dcbab
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
#pragma once
#pragma once
//
//
// base sink templated over a mutex (either dummy or real)
// base sink templated over a mutex (either dummy or real)
// concrete implementation should o
nly override the sink_it_ method
.
// concrete implementation should o
verride the sink_it_() and flush_() methods
.
//
all locking is taken care of here so
no locking needed by the implementers..
//
locking is taken care of in this class -
no locking needed by the implementers..
//
//
#include "spdlog/common.h"
#include "spdlog/common.h"
...
@@ -26,16 +26,6 @@ public:
...
@@ -26,16 +26,6 @@ public:
{
{
}
}
base_sink
(
const
std
::
string
&
formatter_pattern
)
:
sink
(
formatter_pattern
)
{
}
base_sink
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
:
sink
(
std
::
move
(
sink_formatter
))
{
}
base_sink
(
const
base_sink
&
)
=
delete
;
base_sink
(
const
base_sink
&
)
=
delete
;
base_sink
&
operator
=
(
const
base_sink
&
)
=
delete
;
base_sink
&
operator
=
(
const
base_sink
&
)
=
delete
;
...
...
include/spdlog/sinks/
simple
_file_sink.h
→
include/spdlog/sinks/
basic
_file_sink.h
View file @
cd4dcbab
...
@@ -18,10 +18,10 @@ namespace sinks {
...
@@ -18,10 +18,10 @@ namespace sinks {
* Trivial file sink with single file as target
* Trivial file sink with single file as target
*/
*/
template
<
class
Mutex
>
template
<
class
Mutex
>
class
simple
_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
class
basic
_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
{
public
:
public
:
explicit
simple
_file_sink
(
const
filename_t
&
filename
,
bool
truncate
=
false
)
explicit
basic
_file_sink
(
const
filename_t
&
filename
,
bool
truncate
=
false
)
{
{
file_helper_
.
open
(
filename
,
truncate
);
file_helper_
.
open
(
filename
,
truncate
);
}
}
...
@@ -43,8 +43,8 @@ private:
...
@@ -43,8 +43,8 @@ private:
details
::
file_helper
file_helper_
;
details
::
file_helper
file_helper_
;
};
};
using
simple_file_sink_mt
=
simple
_file_sink
<
std
::
mutex
>
;
using
basic_file_sink_mt
=
basic
_file_sink
<
std
::
mutex
>
;
using
simple_file_sink_st
=
simple
_file_sink
<
details
::
null_mutex
>
;
using
basic_file_sink_st
=
basic
_file_sink
<
details
::
null_mutex
>
;
}
// namespace sinks
}
// namespace sinks
...
@@ -54,13 +54,13 @@ using simple_file_sink_st = simple_file_sink<details::null_mutex>;
...
@@ -54,13 +54,13 @@ using simple_file_sink_st = simple_file_sink<details::null_mutex>;
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
basic_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
bool
truncate
=
false
)
inline
std
::
shared_ptr
<
logger
>
basic_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
bool
truncate
=
false
)
{
{
return
Factory
::
template
create
<
sinks
::
simple
_file_sink_mt
>
(
logger_name
,
filename
,
truncate
);
return
Factory
::
template
create
<
sinks
::
basic
_file_sink_mt
>
(
logger_name
,
filename
,
truncate
);
}
}
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
basic_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
bool
truncate
=
false
)
inline
std
::
shared_ptr
<
logger
>
basic_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
bool
truncate
=
false
)
{
{
return
Factory
::
template
create
<
sinks
::
simple
_file_sink_st
>
(
logger_name
,
filename
,
truncate
);
return
Factory
::
template
create
<
sinks
::
basic
_file_sink_st
>
(
logger_name
,
filename
,
truncate
);
}
}
}
// namespace spdlog
}
// namespace spdlog
include/spdlog/sinks/sink.h
View file @
cd4dcbab
...
@@ -18,17 +18,17 @@ public:
...
@@ -18,17 +18,17 @@ public:
:
formatter_
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
"%+"
)))
:
formatter_
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
"%+"
)))
{
{
}
}
//
explicit
sink
(
const
std
::
string
&
formatter_pattern
)
//
explicit sink(const std::string &formatter_pattern)
:
formatter_
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
formatter_pattern
)))
//
: formatter_(std::unique_ptr<spdlog::formatter>(new pattern_formatter(formatter_pattern)))
{
//
{
}
//
}
//
// sink with custom formatter
//
// sink with custom formatter
explicit
sink
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
//
explicit sink(std::unique_ptr<spdlog::formatter> sink_formatter)
:
formatter_
(
std
::
move
(
sink_formatter
))
//
: formatter_(std::move(sink_formatter))
{
//
{
}
//
}
virtual
~
sink
()
=
default
;
virtual
~
sink
()
=
default
;
...
@@ -39,10 +39,12 @@ public:
...
@@ -39,10 +39,12 @@ public:
{
{
return
msg_level
>=
level_
.
load
(
std
::
memory_order_relaxed
);
return
msg_level
>=
level_
.
load
(
std
::
memory_order_relaxed
);
}
}
void
set_level
(
level
::
level_enum
log_level
)
void
set_level
(
level
::
level_enum
log_level
)
{
{
level_
.
store
(
log_level
);
level_
.
store
(
log_level
);
}
}
level
::
level_enum
level
()
const
level
::
level_enum
level
()
const
{
{
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
level_
.
load
(
std
::
memory_order_relaxed
));
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
level_
.
load
(
std
::
memory_order_relaxed
));
...
@@ -58,10 +60,6 @@ public:
...
@@ -58,10 +60,6 @@ public:
formatter_
=
std
::
move
(
sink_formatter
);
formatter_
=
std
::
move
(
sink_formatter
);
}
}
spdlog
::
formatter
*
formatter
()
{
return
formatter_
.
get
();
}
protected
:
protected
:
level_t
level_
{
level
::
trace
};
level_t
level_
{
level
::
trace
};
...
...
include/spdlog/spdlog.h
View file @
cd4dcbab
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
namespace
spdlog
{
namespace
spdlog
{
// Default logger factory- creates synchronous loggers
// Default logger factory- creates synchronous loggers
struct
create_synchronous
struct
synchronous_factory
{
{
template
<
typename
Sink
,
typename
...
SinkArgs
>
template
<
typename
Sink
,
typename
...
SinkArgs
>
...
@@ -32,7 +32,7 @@ struct create_synchronous
...
@@ -32,7 +32,7 @@ struct create_synchronous
}
}
};
};
using
default_factory
=
create_synchronous
;
using
default_factory
=
synchronous_factory
;
// Create and register a logger with a templated sink type
// Create and register a logger with a templated sink type
// The logger's level, formatter and flush level will be set according the global settings.
// The logger's level, formatter and flush level will be set according the global settings.
...
...
tests/errors.cpp
View file @
cd4dcbab
...
@@ -24,7 +24,7 @@ TEST_CASE("default_error_handler", "[errors]]")
...
@@ -24,7 +24,7 @@ TEST_CASE("default_error_handler", "[errors]]")
prepare_logdir
();
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log.txt"
;
std
::
string
filename
=
"logs/simple_log.txt"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"test-error"
,
filename
,
true
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"test-error"
,
filename
,
true
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_pattern
(
"%v"
);
logger
->
info
(
"Test message {} {}"
,
1
);
logger
->
info
(
"Test message {} {}"
,
1
);
logger
->
info
(
"Test message {}"
,
2
);
logger
->
info
(
"Test message {}"
,
2
);
...
@@ -41,7 +41,7 @@ TEST_CASE("custom_error_handler", "[errors]]")
...
@@ -41,7 +41,7 @@ TEST_CASE("custom_error_handler", "[errors]]")
{
{
prepare_logdir
();
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log.txt"
;
std
::
string
filename
=
"logs/simple_log.txt"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"logger"
,
filename
,
true
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"logger"
,
filename
,
true
);
logger
->
flush_on
(
spdlog
::
level
::
info
);
logger
->
flush_on
(
spdlog
::
level
::
info
);
logger
->
set_error_handler
([
=
](
const
std
::
string
&
)
{
throw
custom_ex
();
});
logger
->
set_error_handler
([
=
](
const
std
::
string
&
)
{
throw
custom_ex
();
});
logger
->
info
(
"Good message #1"
);
logger
->
info
(
"Good message #1"
);
...
@@ -75,7 +75,7 @@ TEST_CASE("async_error_handler", "[errors]]")
...
@@ -75,7 +75,7 @@ TEST_CASE("async_error_handler", "[errors]]")
std
::
string
filename
=
"logs/simple_async_log.txt"
;
std
::
string
filename
=
"logs/simple_async_log.txt"
;
{
{
spdlog
::
init_thread_pool
(
128
,
1
);
spdlog
::
init_thread_pool
(
128
,
1
);
auto
logger
=
spdlog
::
create_async
_logger
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"logger"
,
filename
,
true
);
auto
logger
=
spdlog
::
create_async
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"logger"
,
filename
,
true
);
logger
->
set_error_handler
([
=
](
const
std
::
string
&
)
{
logger
->
set_error_handler
([
=
](
const
std
::
string
&
)
{
std
::
ofstream
ofs
(
"logs/custom_err.txt"
);
std
::
ofstream
ofs
(
"logs/custom_err.txt"
);
if
(
!
ofs
)
if
(
!
ofs
)
...
@@ -99,7 +99,7 @@ TEST_CASE("async_error_handler2", "[errors]]")
...
@@ -99,7 +99,7 @@ TEST_CASE("async_error_handler2", "[errors]]")
std
::
string
err_msg
(
"This is async handler error message"
);
std
::
string
err_msg
(
"This is async handler error message"
);
{
{
spdlog
::
init_thread_pool
(
128
,
1
);
spdlog
::
init_thread_pool
(
128
,
1
);
auto
logger
=
spdlog
::
create_async
_logger
<
failing_sink
>
(
"failed_logger"
);
auto
logger
=
spdlog
::
create_async
<
failing_sink
>
(
"failed_logger"
);
logger
->
set_error_handler
([
=
](
const
std
::
string
&
)
{
logger
->
set_error_handler
([
=
](
const
std
::
string
&
)
{
std
::
ofstream
ofs
(
"logs/custom_err2.txt"
);
std
::
ofstream
ofs
(
"logs/custom_err2.txt"
);
if
(
!
ofs
)
if
(
!
ofs
)
...
...
tests/file_log.cpp
View file @
cd4dcbab
...
@@ -8,7 +8,7 @@ TEST_CASE("simple_file_logger", "[simple_logger]]")
...
@@ -8,7 +8,7 @@ TEST_CASE("simple_file_logger", "[simple_logger]]")
prepare_logdir
();
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"logger"
,
filename
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_pattern
(
"%v"
);
logger
->
info
(
"Test message {}"
,
1
);
logger
->
info
(
"Test message {}"
,
1
);
...
@@ -24,7 +24,7 @@ TEST_CASE("flush_on", "[flush_on]]")
...
@@ -24,7 +24,7 @@ TEST_CASE("flush_on", "[flush_on]]")
prepare_logdir
();
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"logger"
,
filename
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
logger
->
flush_on
(
spdlog
::
level
::
info
);
logger
->
flush_on
(
spdlog
::
level
::
info
);
...
...
tests/includes.h
View file @
cd4dcbab
...
@@ -17,6 +17,6 @@
...
@@ -17,6 +17,6 @@
#include "spdlog/sinks/null_sink.h"
#include "spdlog/sinks/null_sink.h"
#include "spdlog/sinks/ostream_sink.h"
#include "spdlog/sinks/ostream_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/
simple
_file_sink.h"
#include "spdlog/sinks/
basic
_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
tests/test_async.cpp
View file @
cd4dcbab
#include "includes.h"
#include "includes.h"
#include "spdlog/async.h"
#include "spdlog/async.h"
#include "spdlog/sinks/
simple
_file_sink.h"
#include "spdlog/sinks/
basic
_file_sink.h"
#include "test_sink.h"
#include "test_sink.h"
TEST_CASE
(
"basic async test "
,
"[async]"
)
TEST_CASE
(
"basic async test "
,
"[async]"
)
...
@@ -121,7 +121,7 @@ TEST_CASE("to_file", "[async]")
...
@@ -121,7 +121,7 @@ TEST_CASE("to_file", "[async]")
size_t
tp_threads
=
1
;
size_t
tp_threads
=
1
;
std
::
string
filename
=
"logs/async_test.log"
;
std
::
string
filename
=
"logs/async_test.log"
;
{
{
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
filename
,
true
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
filename
,
true
);
auto
tp
=
std
::
make_shared
<
spdlog
::
details
::
thread_pool
>
(
messages
,
tp_threads
);
auto
tp
=
std
::
make_shared
<
spdlog
::
details
::
thread_pool
>
(
messages
,
tp_threads
);
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"as"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
));
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"as"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
));
...
@@ -143,7 +143,7 @@ TEST_CASE("to_file multi-workers", "[async]")
...
@@ -143,7 +143,7 @@ TEST_CASE("to_file multi-workers", "[async]")
size_t
tp_threads
=
10
;
size_t
tp_threads
=
10
;
std
::
string
filename
=
"logs/async_test.log"
;
std
::
string
filename
=
"logs/async_test.log"
;
{
{
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
filename
,
true
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
filename
,
true
);
auto
tp
=
std
::
make_shared
<
spdlog
::
details
::
thread_pool
>
(
messages
,
tp_threads
);
auto
tp
=
std
::
make_shared
<
spdlog
::
details
::
thread_pool
>
(
messages
,
tp_threads
);
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"as"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
));
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"as"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
));
...
...
tests/test_macros.cpp
View file @
cd4dcbab
...
@@ -9,12 +9,11 @@ TEST_CASE("debug and trace w/o format string", "[macros]]")
...
@@ -9,12 +9,11 @@ TEST_CASE("debug and trace w/o format string", "[macros]]")
prepare_logdir
();
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"logger"
,
filename
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
SPDLOG_TRACE
(
logger
,
"Test message 1"
);
SPDLOG_TRACE
(
logger
,
"Test message 1"
);
// SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message 2"
);
SPDLOG_DEBUG
(
logger
,
"Test message 2"
);
logger
->
flush
();
logger
->
flush
();
...
@@ -27,7 +26,7 @@ TEST_CASE("debug and trace with format strings", "[macros]]")
...
@@ -27,7 +26,7 @@ TEST_CASE("debug and trace with format strings", "[macros]]")
prepare_logdir
();
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple
_file_sink_mt
>
(
"logger"
,
filename
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
basic
_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
...
...
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