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
Conversation
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.
Nice! |
Allow customizing the naming convention for log files to use timestamps.
NSDate *now = [NSDate date]; | ||
|
||
// RFC 3339 format, UTC time | ||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
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.
we could make this NSDateFormatter reusable (i.e. static) to improve performance
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.
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.
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.
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.
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.
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.
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.
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.
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.