Skip to content

FileRotationLogger crashes when archiving full log files #10

@tucknology

Description

@tucknology

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions