The LXLogHTTPJSONEndpoint uploads Log Entries to an HTTP service. The Entries are serialized in JSON format.

Upload and retry management are handled automatically by this Endpoint. Log Entries that do not successfully upload will be queued for another attempt at a later time. However, pending uploads are not persisted between application runs.

This Endpoint attempts to deliver Log Entries in the order in which they were generated, but because network performance is very unpredictable, this is not guaranteed.

The HTTP JSON 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 HTTP JSON 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.

Entry Formatting

The HTTP JSON Endpoint is hard-coded to include a special entryFormatter that converts each Log Entry to a dictionary, then JSON serializes it for upload. This formatter includes all properties of a Log Entry, including the Entry’s userInfo. Each Log Entry property becomes a top-level item in the dictionary. Any top-level items in an Entry’s userInfo will become top-level items with the rest of an Entry’s properties. Dictionary key conflicts between userInfo’s items and an Entry’s properties will result in userInfo’s conflicted items being overwritten by the Entry’s items. Developer beware.

It is the application developer’s duty to ensure that all userInfo items are JSON-serializable if this Endpoint is in use. A non-JSON-serializable item will cause the Log Entry to be skipped in a shipping application (though in a test build, the application will abort).



The following initializers are available for LXLogHTTPJSONEndpoint:

init(URL: HTTPMethod: successCodes: sessionConfiguration: minimumLogLevel: dateFormatter: )


The URL to upload Log Entries to
HTTPMethod Type: String
The HTTP request method to be used when uploading Log Entries
successCodes Type: Set<Int>
Default: {200, 201, 202, 204}
The set of HTTP status codes the server might respond with to indicate a successful upload
sessionConfiguration Type: NSURLSessionConfiguration
Default: .defaultSessionConfiguration()
The configuration to be used when initializing this Endpoint’s URL session
minimumLogLevel Type: LXLogLevel
Default: .All
The minimum Priority Level a Log Entry must meet to be accepted by this Endpoint
dateFormatter Type: NSDateFormatter
Default: default date formatter
The formatter used by this Endpoint to serialize a Log Entry’s dateTime property to a string

This Endpoint will upload Log Entries to the specified URL using the specified HTTPMethod. The Endpoint will create a basic application/json NSURLRequest object to be used for all Log Entry uploads. Developers that require more flexibility in configuring upload requests may investigate supplying a customized NSURLSessionConfiguration.

Returns an initialized HTTP JSON Endpoint instance. This Endpoint uses a specialized entryFormatter described above.