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
2463fe92
Unverified
Commit
2463fe92
authored
Jan 24, 2019
by
Gabi Melman
Committed by
GitHub
Jan 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #958 from pwm1234/pwm1234/rotate_on_open
Pwm1234/rotate on open
parents
3466c9c8
4f65fcd7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
+23
-6
rotating_file_sink.h
include/spdlog/sinks/rotating_file_sink.h
+9
-5
test_file_logging.cpp
tests/test_file_logging.cpp
+14
-1
No files found.
include/spdlog/sinks/rotating_file_sink.h
View file @
2463fe92
...
...
@@ -31,13 +31,17 @@ template<typename Mutex>
class
rotating_file_sink
final
:
public
base_sink
<
Mutex
>
{
public
:
rotating_file_sink
(
filename_t
base_filename
,
std
::
size_t
max_size
,
std
::
size_t
max_files
)
rotating_file_sink
(
filename_t
base_filename
,
std
::
size_t
max_size
,
std
::
size_t
max_files
,
bool
rotate_on_open
=
false
)
:
base_filename_
(
std
::
move
(
base_filename
))
,
max_size_
(
max_size
)
,
max_files_
(
max_files
)
{
file_helper_
.
open
(
calc_filename
(
base_filename_
,
0
));
current_size_
=
file_helper_
.
size
();
// expensive. called only once
if
(
rotate_on_open
&&
current_size_
>
0
)
{
rotate_
();
}
}
// calc filename according to index and file extension if exists.
...
...
@@ -146,15 +150,15 @@ using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
)
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
rotate_on_open
=
false
)
{
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
max_file_size
,
max_files
);
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
max_file_size
,
max_files
,
rotate_on_open
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
)
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
rotate_on_open
=
false
)
{
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
max_file_size
,
max_files
);
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
max_file_size
,
max_files
,
rotate_on_open
);
}
}
// namespace spdlog
tests/test_file_logging.cpp
View file @
2463fe92
...
...
@@ -60,7 +60,20 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
prepare_logdir
();
size_t
max_size
=
1024
*
10
;
std
::
string
basename
=
"logs/rotating_log"
;
auto
logger
=
spdlog
::
rotating_logger_mt
(
"logger"
,
basename
,
max_size
,
1
);
{
// make an initial logger to create the first output file
auto
logger
=
spdlog
::
rotating_logger_mt
(
"logger"
,
basename
,
max_size
,
2
,
true
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
logger
->
info
(
"Test message {}"
,
i
);
}
// drop causes the logger destructor to be called, which is required so the
// next logger can rename the first output file.
spdlog
::
drop
(
logger
->
name
());
}
auto
logger
=
spdlog
::
rotating_logger_mt
(
"logger"
,
basename
,
max_size
,
2
,
true
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
logger
->
info
(
"Test message {}"
,
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