Skip to content
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

FileRotationLogger crashes when archiving full log files #10

Closed
tucknology opened this issue Apr 14, 2021 · 4 comments · Fixed by #11
Closed

FileRotationLogger crashes when archiving full log files #10

tucknology opened this issue Apr 14, 2021 · 4 comments · Fixed by #11

Comments

@tucknology
Copy link

tucknology commented Apr 14, 2021

Hi!

In FileRotationLogger.swift the function rotateFiles() fails at line 109 during the following instruction:

try FileManager.default.moveItem(at: fileURL, to: archivedFileURL)

This happens because in Formatter.swift the function dateFormatter(_:, locale:, dateFormat:, timeZone:) creates a timestamp that includes colons (:) which the file system does not like.

One potential solution is changing the dateFormat in line 13 of Formatter.swift from "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" to "yyyy-MM-dd'T'HH-mm-ss.SSS". This removes the explicit colons in the original date format string, as well as an implicit colon which is added by ZZZZZ which expands to an HH:MM style presentation of the timezone.

You might also consider reducing the complexity of this string further, since I'd argue if a detailed timestamp is necessary then it can be placed inside the log file, rather than in the file name.

One alternative could be to structure like this:

myLog.log
myLog.log.1
myLog.log.2

This proposal would simplify the implementation of the rest of the rotateFiles method that is concerned with removing old archived files.

@sushichop
Copy link
Owner

sushichop commented Apr 19, 2021

@tucknology
Thanks for reporting this. I decided not to use colon.
And for now I still want to handle the case someone wants to check the date without opening the file.
So I'll use ISO8601 basic format (no-hyphen and GMT) instead of extended format and this fixes the issue with small change.
See #11 .

One alternative could be to structure like this:

myLog.log
myLog.log.1
myLog.log.2

This is another good idea!
I'll also consider this solution in the future. It will need more big change in the code. Then I have created this issue in order to keep in mind (#12).

Thanks.

@sushichop
Copy link
Owner

sushichop commented Apr 30, 2021

I'm closing this issue since it was fixed by #11,
Feel free to reopen it or create a new issue if you will have any questions.

Thanks.

@sushichop
Copy link
Owner

One alternative could be to structure like this:

myLog.log
myLog.log.1
myLog.log.2

I have adde this feature. See #32.

Thanks.

@sushichop
Copy link
Owner

I have released Puppy@0.4.0 that fixes this issue.
Check release note and README because some specifications of FileLogger and FileRotationLogger have been changed.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants