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
3925f8fa
Commit
3925f8fa
authored
Jan 24, 2019
by
Philip Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
streamline constructor logic
and improve test for rotate_on_open=true
parent
cce1e36e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
rotating_file_sink.h
include/spdlog/sinks/rotating_file_sink.h
+16
-4
test_file_logging.cpp
tests/test_file_logging.cpp
+16
-3
No files found.
include/spdlog/sinks/rotating_file_sink.h
View file @
3925f8fa
...
...
@@ -36,9 +36,14 @@ public:
,
max_size_
(
max_size
)
,
max_files_
(
max_files
)
{
file_helper_
.
open
(
calc_filename
(
base_filename_
,
0
));
if
(
rotate_on_open
)
rotate_
();
{
rotate_
(
false
);
}
else
{
file_helper_
.
open
(
calc_filename
(
base_filename_
,
0
));
}
current_size_
=
file_helper_
.
size
();
// expensive. called only once
}
...
...
@@ -90,7 +95,7 @@ private:
// log.1.txt -> log.2.txt
// log.2.txt -> log.3.txt
// log.3.txt -> delete
void
rotate_
()
void
rotate_
(
bool
reopen
=
true
)
{
using
details
::
os
::
filename_to_str
;
file_helper_
.
close
();
...
...
@@ -118,7 +123,14 @@ private:
}
}
}
file_helper_
.
reopen
(
true
);
if
(
reopen
)
{
file_helper_
.
reopen
(
true
);
}
else
{
file_helper_
.
open
(
base_filename_
,
true
);
}
}
// delete the target if exists, and rename the src file to target
...
...
tests/test_file_logging.cpp
View file @
3925f8fa
...
...
@@ -38,7 +38,7 @@ TEST_CASE("flush_on", "[flush_on]]")
REQUIRE
(
count_lines
(
filename
)
==
3
);
}
TEST_CASE
(
"rotating_file_logger
1
"
,
"[rotating_logger]]"
)
TEST_CASE
(
"rotating_file_logger"
,
"[rotating_logger]]"
)
{
prepare_logdir
();
size_t
max_size
=
1024
*
10
;
...
...
@@ -55,12 +55,25 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
REQUIRE
(
count_lines
(
filename
)
==
10
);
}
TEST_CASE
(
"rotating_file_logger2"
,
"[rotating_logger]]"
)
TEST_CASE
(
"rotating_file_logger2"
,
"[rotating_logger
2
]]"
)
{
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
,
true
);
{
// 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