8000 Merge. by wilx · Pull Request #522 · log4cplus/log4cplus · GitHub
[go: up one dir, main page]

Skip to content

Merge. #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
filename should not be empty for TimeBasedRollingFileAppender
TimeBasedRollingFileAppender uses `filenamePattern` alone with
current date time as opened filename and `filename` field is left
empty almost all the time. This brings the problem when it calls
`append()` method from the base class FileAppenderBase.
The base class FileAppenderBase assumes that `filename` field is
the path for opened file. Now this contract is broken.

Currently, this will cause log4cplus to print
"log4cplus: ERROR file is not open:"
when `out` stream is broken. It's confusing and misleading.
Users may think that log4cplus tries to open a file with
the empty name "".

This does not stop here, as long as it persists, more
subtle bugs can be introduced.

This commit fixes this problem by setting filename to the
name of current opened file in
`TimeBasedRollingFileAppender::open()`
making the contract valid again.

Signed-off-by: foxhlchen <foxhlchen@gmail.com>
  • Loading branch information
foxhlchen authored and wilx committed Aug 15, 2021
commit 917b5c413ae2f935ad57e27af68cc95d6e13124e
7 changes: 5 additions & 2 deletions src/fileappender.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,10 @@ void
TimeBasedRollingFileAppender::open(std::ios_base::openmode mode)
{
scheduledFilename = helpers::getFormattedTime(filenamePattern, helpers::now(), false);
tstring currentFilename = filename.empty() ? scheduledFilename : filename;
if (filename.empty())
filename = scheduledFilename;

tstring currentFilename = filename;

if (createDirs)
internal::make_dirs (currentFilename);
Expand Down Expand Up @@ -1397,7 +1400,7 @@ TimeBasedRollingFileAppender::rollover(bool alreadyLocked)
// should remain unchanged on a close
out.clear();

if (! filename.empty())
if (filename != scheduledFilename)
{
helpers::LogLog & loglog = helpers::getLogLog();
long ret;
Expand Down
0