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
2fa7410c
Commit
2fa7410c
authored
Sep 17, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve rotating sink error handling
parent
3771d129
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
rotating_file_sink.h
include/spdlog/sinks/rotating_file_sink.h
+19
-13
No files found.
include/spdlog/sinks/rotating_file_sink.h
View file @
2fa7410c
...
...
@@ -86,24 +86,21 @@ private:
for
(
auto
i
=
max_files_
;
i
>
0
;
--
i
)
{
filename_t
src
=
calc_filename
(
base_filename_
,
i
-
1
);
filename_t
target
=
calc_filename
(
base_filename_
,
i
);
if
(
details
::
file_helper
::
file_exists
(
target
))
{
if
(
details
::
os
::
remove
(
target
)
!=
0
)
if
(
!
details
::
file_helper
::
file_exists
(
src
))
{
throw
spdlog_ex
(
"rotating_file_sink: failed removing "
+
filename_to_str
(
target
),
errno
);
continue
;
}
}
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
details
::
os
::
rename
(
src
,
target
)
!=
0
)
filename_t
target
=
calc_filename
(
base_filename_
,
i
);
if
(
!
rename_file
(
src
,
target
))
{
// if failed try again after
small delay.
// if failed try again after
a small delay.
// this is a workaround to a windows issue, where very high rotation
// rates sometimes fail (because of antivirus?).
details
::
os
::
sleep_for_millis
(
20
);
details
::
os
::
remove
(
target
);
if
(
details
::
os
::
rename
(
src
,
target
)
!=
0
)
// rates can cause the rename to fail with permission denied (because of antivirus?).
details
::
os
::
sleep_for_millis
(
100
);
if
(
!
rename_file
(
src
,
target
))
{
file_helper_
.
reopen
(
true
);
// truncate the log file anyway to prevent it to grow beyond its limit!
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
),
errno
);
}
...
...
@@ -112,6 +109,15 @@ private:
file_helper_
.
reopen
(
true
);
}
// delete the target if exists, and rename the src file to target
// return true on success, false otherwise.
bool
rename_file
(
const
filename_t
&
src_filename
,
const
filename_t
&
target_filename
)
{
// try to delete the target file in case it already exists.
(
void
)
details
::
os
::
remove
(
target_filename
);
return
details
::
os
::
rename
(
src_filename
,
target_filename
)
==
0
;
}
filename_t
base_filename_
;
std
::
size_t
max_size_
;
std
::
size_t
max_files_
;
...
...
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