GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add support for rolling logfile names in FileAppender (and Logger) by kiesel · Pull Request #353 · xp-framework/xp-framework

This repository was archived by the owner on Apr 5, 2020. It is now read-only.

Conversation

@kiesel

@kiesel kiesel commented Mar 11, 2014

Copy link
Copy Markdown
Member

For long running applications, the FileAppender would only once create a filename for the logfile to append; this means, using a filename such as myapp-%Y-%m-%d.log would write to one file forever, until the app restarts.

This PR adds support for re-calculating the filename on every append, thus if a marker rolls over, it results in a new file being written to. Old behaviour can still be triggered by setting the new member syncDate to false (true is the new default).

/cc @haimich

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alex Kiesel added 3 commits March 10, 2014 09:21
Alex Kiesel
- replace strftime tokens in FileAppender
8bec35f
Add a setting to support legacy behavior (syncDate)
Alex Kiesel
Do not apply strftime to params
c1104d5
in the Logger; this is the appenders responsibility now
Alex Kiesel
- set correct file permissions upon every write
07081dd
It may not be done only once, because we will have new log files
being created after a new filename was given, so we could have
a new file w/ new perms at any given run
@thekid

thekid commented Mar 11, 2014

Copy link
Copy Markdown
Member
  • You need to fix PHP Fatal error: Call to undefined function strfime() in .../util/log/FileAppender.class.php on line 45 before we can merge this.
  • There should be unittests
  • Think about using file_put_contents() with the append flag instead of the fopen, fwrite, fclose trio.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Alex Kiesel added 2 commits March 11, 2014 09:32
Alex Kiesel
- use file_put_contents() call instead of fopen() combo
8edb903
- fix typo in strftime()
Alex Kiesel
- fix stream wrapper to return amount of actual written bytes
df30497
  (file_put_contents() checks this and reports error when given !=
  written)
- add (slow) test coverage for filename calculation
@kiesel

kiesel commented Mar 11, 2014

Copy link
Copy Markdown
Member Author

Thanks, corrected / incorporated these three suggestions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thekid thekid added the feature label Mar 11, 2014
@thekid

thekid commented Mar 12, 2014

Copy link
Copy Markdown
Member

corrected / incorporated these three suggestions.

...but forgot to push them, @kiesel?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kiesel

kiesel commented Mar 12, 2014

Copy link
Copy Markdown
Member Author

Obviously. Pushed now. Thanks for the headsup, @thekid ..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thekid
thekid reviewed Mar 13, 2014
View reviewed changes
Comment thread core/src/main/php/util/log/FileAppender.class.php Outdated

@thekid thekid Mar 13, 2014

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unconditional chmod call will change the file's permissions to octdec(NULL) == 0. You should initialize the perms member with something useful, e.g. 644, or 600.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thekid added 6 commits March 15, 2014 13:30
@thekid
QA: Coding standards adjustments
fbb0c9f
@thekid
Use fresh file for every test
1125655
@thekid
Ensure file mode is always set
e439019
@thekid
Fix chmod(000) if "perms" member is left uninitialized
e2bb7e5
@thekid
Rewrite test to not rely on timing anymore
bd5e65e
@thekid
QA: Simplify code
3be43c3
@thekid

thekid commented Mar 15, 2014

Copy link
Copy Markdown
Member

I incorporated a couple of changes, @kiesel:

  • I fixed the chmod(0) issue.
  • I changed the test with sleep(1) inside to not rely on timing.
  • I simplified the code a bit.

Please have a look and if OK, go ahead and merge!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kiesel

kiesel commented Mar 17, 2014

Copy link
Copy Markdown
Member Author

Hm, what do you actually test? I'd say you don't test that the filename is properly strftime()d... The base method is completely overwritten, thus you cannot test the contained code.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thekid

thekid commented Mar 17, 2014

Copy link
Copy Markdown
Member

Hm, what do you actually test?

I test that if filename() returns a different filename, then it gets used instead of the one I pass into the constructor.

But you're right, we should maybe also test the strftime call works properly. How about extracting the strftime calls to a formatDate() method, or - alternatively - add an optional parameter date to the filename() method?

Anyhow, not relying on timing anymore seems to be agreeable for you, too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kiesel

kiesel commented Mar 17, 2014

Copy link
Copy Markdown
Member Author

I also thought about adding this parameter, but would still not be easily possible to have a fixed date be passed within the append() method. Anyhow, probably we don't need to make sure strftime() does work, because the PHP Group does that already (hopefully).

I think we can leave it as is, then, and finally merge this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thekid added 2 commits March 17, 2014 20:34
@thekid
Also include inner workings of filename() in test
1c45d2d
@thekid
Use test file system
a411a10
@thekid

thekid commented Mar 17, 2014

Copy link
Copy Markdown
Member

Here we go, no includes an optional $ref date parameter. Your call, either revert or merge:)

.oO(ping 🎾 pong) 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kiesel added a commit that referenced this pull request Mar 17, 2014
@kiesel
Merge pull request #353 from kiesel/rolling-logfiles
4170e53
- add support for rolling logfile names in util.log.FileAppender (and util.log.Logger)
@kiesel
kiesel merged commit 4170e53 into xp-framework:master Mar 17, 2014
@kiesel

kiesel commented Mar 17, 2014

Copy link
Copy Markdown
Member Author

Merged #353.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kiesel pushed a commit that referenced this pull request Mar 17, 2014
Alex Kiesel
- Register issue #353 in ChangeLog
9899027
@thekid

thekid commented Mar 17, 2014

Copy link
Copy Markdown
Member

Cool! Can we also apply this to 6.0?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kiesel

kiesel commented Mar 17, 2014

Copy link
Copy Markdown
Member Author

Yes, but travis reported we broke the build @ PHP 5.3.0 - because the STREAM_META_* constants and their features came w/ 5.4 :-/ So, actually this is not an issue for XP 6, but we need to deal with it for 5.9.* ...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thekid

thekid commented Mar 17, 2014

Copy link
Copy Markdown
Member

Yes, but travis reported we broke the build @ PHP 5.3.0

Fixed by 5966c83 - caused by the file_exists() calls in the newly introduced filename_syncs_with_time tests which now calls into url_stat() and thus accessed STREAM_META_ACCESS. Fixed by guarding with if.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thekid

thekid commented Mar 17, 2014

Copy link
Copy Markdown
Member

All these if guards could easily be rewritten to @actions using xp-framework/rfc#283 if they weren't obsolete in XP 6 (req: PHP 5.4+) anyway:)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Mar 18, 2014
Think about adding log rotation for xpcli scripts #351
Closed
RollingFileAppender xp-framework/rfc#64
Closed
thekid added a commit to xp-framework/core that referenced this pull request Mar 18, 2014
@thekid
MFB: Add support for rolling logfile names in FileAppender
d09cf37
  and Logger - see xp-framework/xp-framework#353
@thekid

thekid commented Mar 18, 2014

Copy link
Copy Markdown
Member

6️⃣ - Merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kiesel

kiesel commented Mar 18, 2014

Copy link
Copy Markdown
Member Author

👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

feature

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kiesel @thekid
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.