Dated File Endpoint
The LXDatedFileEndpoint
writes Log Entries to a selected file, which changes a daily. Developers can specify a base URL for the log files, and the Endpoint will prepend the current datestamp to each file’s name. At each midnight UTC, the Endpoint will create a new dated file for that day’s logging.
The Dated File Endpoint is safe to be used in environments featuring concurrency. This Endpoint does some of its work asynchronously to allow better logging performance. Because the Dated File Endpoint takes advantage of asynchronous technologies, Log Entries written to this Endpoint may not appear until slightly after execution has moved on. In other words, if your application attempts to create a Log Entry directly before it crashes, it may not be delivered before the crash occurs. While debugging your application, if the asynchronous nature of this Endpoint is problematic, consider using a synchronous Console Endpoint in addition.
Usage
Initializers
The following initializers are available for LXDatedFileEndpoint
:
Parameters
baseURL |
Type: NSURL? Default: see below |
The URL used to build the date files’ URLs; see description below |
minimumPriorityLevel |
Type: LXPriorityLevel Default: .All |
The minimum Priority Level a Log Entry must meet to be accepted by this Endpoint |
dateFormatter |
Type: LXDateFormatter Default: .standardFormatter() |
The formatter used by this Endpoint to serialize a Log Entry’s dateTime property to a string |
entryFormatter |
Type: LXEntryFormatter Default: .standardFormatter() |
The formatter used by this Endpoint to serialize each Log Entry to a string |
This Endpoint writes Log Entries to a series of files specified by baseURL
, with each file’s name automatically prepended with a UTC datestamp in the format yyyy-MM-dd
. If the specified file cannot be opened, or if the datestamp-prepended URL evaluates to nil
, the initializer may fail.
If omitted, the URL defaults to {AppSupport}/{bundleID}/logs/{datestamp}_log.txt
, where {AppSupport}
is the system-determined Application Support directory, {bundleID}
is the host application’s bundleIdentifier
string, and {datestamp}
is the current UTC date’s datestamp.
As an example, if an LXDatedFileEndpoint
is initialized with its default parameter values and today’s date is October 5, 2015, it will create a file in Application Support/{bundleID}/logs/
named 2015-10-05_log.txt
. At midnight UTC, Log Entries will automatically begin being written to a new file named 2015-10-06_log.txt
.
Returns an initialized Dated File Endpoint instance if successful, or nil
if the file cannot be opened.