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

Allow customizing the naming convention for log files to use timestamps. #174

Merged
merged 1 commit into from Nov 26, 2013

Conversation

michaelmelanson
Copy link
Contributor

We find UUIDs to quite awkward in the field because the files cannot be
sorted in chronological order by filename. This patch adds an optional
convention to the DDLogFileManagerDefault class which uses timestamps
instead. The existing UUID-based naming convention is retained as the
default convention for backwards compatibility.

Timestamps are formatted as RFC 3339 dates in the UTC time zone.

We find UUIDs to quite awkward in the field because the files cannot be
sorted in chronological order by filename. This patch adds an optional
convention to the DDLogFileManagerDefault class which uses timestamps
instead. The existing UUID-based naming convention is retained as the
default convention for backwards compatibility.

Timestamps are formatted as RFC 3339 dates in the UTC time zone.
@rivera-ernesto
Copy link
Member

Nice!

rivera-ernesto pushed a commit that referenced this pull request Nov 26, 2013
Allow customizing the naming convention for log files to use timestamps.
@rivera-ernesto rivera-ernesto merged commit a802320 into CocoaLumberjack:master Nov 26, 2013
NSDate *now = [NSDate date];

// RFC 3339 format, UTC time
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
Copy link
Member

Choose a reason for hiding this comment

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

we could make this NSDateFormatter reusable (i.e. static) to improve performance

Copy link
Member

Choose a reason for hiding this comment

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

Right. It would suffice to add the static keyword on this line.

On the other hand this is only called when creating new files, which is far less often than when sending a new log message.

Copy link
Member

Choose a reason for hiding this comment

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

We could leave it as it is, but from experience, you never know when you start using that method more often. I think it's a good practice to always reuse NSFormatters.

Choose a reason for hiding this comment

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

Just remember that NSDateFormatter is not thread safe https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

I have not looked closely to see if this method is (or can be) called from multiple threads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly guys, I don't think this is something worth optimizing. Unless someone is rotating their logs very very frequently (OTOO several times a second, which would be silly), there's no way creating a date formatter object each time will have any significant performance impact.

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 this pull request may close these issues.

None yet

4 participants