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
032035e7
Commit
032035e7
authored
Jun 10, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
66b5772b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
38 deletions
+34
-38
step_file_sink.h
include/spdlog/contrib/sinks/step_file_sink.h
+19
-11
async_log_helper.h
include/spdlog/details/async_log_helper.h
+13
-25
async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+2
-2
No files found.
include/spdlog/contrib/sinks/step_file_sink.h
View file @
032035e7
...
...
@@ -18,22 +18,26 @@
// Create a file logger which creates new files with a specified time step and fixed file size:
//
// std::shared_ptr<logger> step_logger_mt(const std::string &logger_name, const filename_t &filename, unsigned seconds = 60, const
// filename_t &tmp_ext = ".tmp", unsigned max_file_size = std::numeric_limits<unsigned>::max(), bool delete_empty_files = true, const
filename_t &file_header = ""); std::shared_ptr<logger>
//
step_logger_st(const std::string &logger_name, const filename_t &filename, unsigned seconds = 60, const filename_t &tmp_ext = ".tmp"
,
// unsigned max_file_size = std::numeric_limits<unsigned>::max());
// filename_t &tmp_ext = ".tmp", unsigned max_file_size = std::numeric_limits<unsigned>::max(), bool delete_empty_files = true, const
//
filename_t &file_header = ""); std::shared_ptr<logger> step_logger_st(const std::string &logger_name, const filename_t &filename
,
// unsigned
seconds = 60, const filename_t &tmp_ext = ".tmp", unsigned
max_file_size = std::numeric_limits<unsigned>::max());
// Example for spdlog_impl.h
// Create a file logger that creates new files with a specified increment
// inline std::shared_ptr<spdlog::logger> spdlog::step_logger_mt(
// const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size, bool delete_empty_files, const filename_t &file_header)
// const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size,
// bool delete_empty_files, const filename_t &file_header)
// {
// return create<spdlog::sinks::step_file_sink_mt>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files, file_header);
// return create<spdlog::sinks::step_file_sink_mt>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files,
// file_header);
// }
// inline std::shared_ptr<spdlog::logger> spdlog::step_logger_st(
// const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size, bool delete_empty_files, const filename_t &file_header)
// const std::string &logger_name, const filename_t &filename_fmt, unsigned seconds, const filename_t &tmp_ext, unsigned max_file_size,
// bool delete_empty_files, const filename_t &file_header)
// {
// return create<spdlog::sinks::step_file_sink_st>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files, file_header);
// return create<spdlog::sinks::step_file_sink_st>(logger_name, filename_fmt, seconds, tmp_ext, max_file_size, delete_empty_files,
// file_header);
// }
namespace
spdlog
{
...
...
@@ -64,7 +68,8 @@ template<class Mutex, class FileNameCalc = default_step_file_name_calculator>
class
step_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
step_file_sink
(
filename_t
base_filename
,
unsigned
step_seconds
,
filename_t
tmp_ext
,
unsigned
max_size
,
bool
delete_empty_files
,
filename_t
file_header
)
step_file_sink
(
filename_t
base_filename
,
unsigned
step_seconds
,
filename_t
tmp_ext
,
unsigned
max_size
,
bool
delete_empty_files
,
filename_t
file_header
)
:
_base_filename
(
std
::
move
(
base_filename
))
,
_tmp_ext
(
std
::
move
(
tmp_ext
))
,
_step_seconds
(
step_seconds
)
...
...
@@ -102,7 +107,8 @@ public:
if
(
!
_current_size
)
{
_current_size
+=
_file_header
.
formatted
.
size
();
if
(
_current_size
)
_file_helper
.
write
(
_file_header
);
if
(
_current_size
)
_file_helper
.
write
(
_file_header
);
}
}
...
...
@@ -142,7 +148,8 @@ protected:
if
(
change_occured
)
{
_current_size
=
_file_header
.
formatted
.
size
();
if
(
_current_size
)
_file_helper
.
write
(
_file_header
);
if
(
_current_size
)
_file_helper
.
write
(
_file_header
);
}
}
...
...
@@ -182,7 +189,8 @@ private:
if
(
details
::
file_helper
::
file_exists
(
_current_filename
)
&&
details
::
os
::
rename
(
_current_filename
,
target
)
!=
0
)
{
throw
spdlog_ex
(
"step_file_sink: failed renaming "
+
filename_to_str
(
_current_filename
)
+
" to "
+
filename_to_str
(
target
),
errno
);
throw
spdlog_ex
(
"step_file_sink: failed renaming "
+
filename_to_str
(
_current_filename
)
+
" to "
+
filename_to_str
(
target
),
errno
);
}
}
...
...
include/spdlog/details/async_log_helper.h
View file @
032035e7
...
...
@@ -29,13 +29,11 @@
#include <utility>
#include <vector>
namespace
spdlog
{
namespace
details
{
namespace
details
{
class
async_log_helper
{
class
async_log_helper
{
// Async msg to move to/from the queue
// Movable only. should never be copied
enum
class
async_msg_type
...
...
@@ -84,7 +82,7 @@ namespace spdlog {
}
// copy into log_msg
void
fill_log_msg
(
log_msg
&
msg
,
std
::
string
*
logger_name
)
void
fill_log_msg
(
log_msg
&
msg
,
std
::
string
*
logger_name
)
{
msg
.
logger_name
=
logger_name
;
msg
.
level
=
level
;
...
...
@@ -96,18 +94,14 @@ namespace spdlog {
}
};
public
:
public
:
using
item_type
=
async_msg
;
using
q_type
=
details
::
mpmc_bounded_queue
<
item_type
>
;
using
clock
=
std
::
chrono
::
steady_clock
;
async_log_helper
(
std
::
string
logger_name
,
formatter_ptr
formatter
,
std
::
vector
<
sink_ptr
>
sinks
,
size_t
queue_size
,
const
log_err_handler
err_handler
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
async_log_helper
(
std
::
string
logger_name
,
formatter_ptr
formatter
,
std
::
vector
<
sink_ptr
>
sinks
,
size_t
queue_size
,
const
log_err_handler
err_handler
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
std
::
function
<
void
()
>
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
std
::
function
<
void
()
>
worker_teardown_cb
=
nullptr
);
...
...
@@ -126,7 +120,7 @@ namespace spdlog {
void
set_error_handler
(
spdlog
::
log_err_handler
err_handler
);
private
:
private
:
std
::
string
_logger_name
;
formatter_ptr
_formatter
;
std
::
vector
<
std
::
shared_ptr
<
sinks
::
sink
>>
_sinks
;
...
...
@@ -170,22 +164,16 @@ namespace spdlog {
void
handle_flush_interval
();
void
flush_sinks
();
};
}
// namespace details
};
}
// namespace details
}
// namespace spdlog
///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation
///////////////////////////////////////////////////////////////////////////////
inline
spdlog
::
details
::
async_log_helper
::
async_log_helper
(
std
::
string
logger_name
,
formatter_ptr
formatter
,
std
::
vector
<
sink_ptr
>
sinks
,
size_t
queue_size
,
log_err_handler
err_handler
,
const
async_overflow_policy
overflow_policy
,
std
::
function
<
void
()
>
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
,
std
::
function
<
void
()
>
worker_teardown_cb
)
inline
spdlog
::
details
::
async_log_helper
::
async_log_helper
(
std
::
string
logger_name
,
formatter_ptr
formatter
,
std
::
vector
<
sink_ptr
>
sinks
,
size_t
queue_size
,
log_err_handler
err_handler
,
const
async_overflow_policy
overflow_policy
,
std
::
function
<
void
()
>
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
,
std
::
function
<
void
()
>
worker_teardown_cb
)
:
_logger_name
(
std
::
move
(
logger_name
))
,
_formatter
(
std
::
move
(
formatter
))
,
_sinks
(
std
::
move
(
sinks
))
...
...
include/spdlog/details/async_logger_impl.h
View file @
032035e7
...
...
@@ -21,8 +21,8 @@ inline spdlog::async_logger::async_logger(const std::string &logger_name, const
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>
&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
,
const
std
::
function
<
void
()
>
&
worker_teardown_cb
)
:
logger
(
logger_name
,
begin
,
end
)
,
_async_log_helper
(
new
details
::
async_log_helper
(
logger_name
,
_formatter
,
_sinks
,
queue_size
,
_err_handler
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
))
,
_async_log_helper
(
new
details
::
async_log_helper
(
logger_name
,
_formatter
,
_sinks
,
queue_size
,
_err_handler
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
))
{
}
...
...
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