Endpoints
Endpoints are responsible for processing and writing Log Entries to the destinations they represent. LogKit includes several built-in Endpoints for various logging needs, but application developers can also create their own.
Endpoints are specified when a Logger instance is initialized. A Logger instance can include several Endpoints, and each Endpoint can be configured independently.
Included Endpoints
LogKit includes the following Endpoints ready for use:
- Console Endpoint
- File Endpoint
- Rotating File Endpoint
- Dated File Endpoint
- HTTP Endpoint
- HTTP JSON Endpoint
Each of these included Endpoint types has unique settings and characteristics. View each specific Endpoint’s documentation to learn about initializing and using that Endpoint.
Creating a Custom Endpoint
If the included Endpoint types do not meet your needs, LogKit makes it easy to create a custom Endpoint for use within your application. Simply define an object that conforms to LogKit’s Endpoint protocol, and include it when initializing your Logger. The protocol defines a few properties that control which Log Entries an Endpoint will accept and how the Entries will be formatted, as well as a method for writing Log Entries to the destination the Endpoint represents.
The Endpoint Protocol
The LXEndpoint
protocol defines the following required properties:
minimumPriorityLevel |
LXPriorityLevel |
The minimum Priority Level a Log Entry must meet to be accepted by this Endpoint |
dateFormatter |
LXDateFormatter |
The formatter used by this Endpoint to serialize a Log Entry’s dateTime property to a string |
entryFormatter |
LXEntryFormatter |
The formatter used by this Endpoint to serialize each Log Entry to a string |
requiresNewlines |
Bool |
Indicates whether this Endpoint requires a newline character appended to each serialized Log Entry string |
When a Log Entry meets an Endpoint’s Priority Level requirements, and has been serialized to a string by the Endpoint’s formatters, that string is passed to the Endpoint’s write:
method for output to its final destination. In the write:
method, an Endpoint creator should print the string
to the console, append it to a log file, or send it to whatever destination your Endpoint represents.
write(string:String) |
Writes a serialized Log Entry string to the final destination this Endpoint represents |
Example Endpoint
Below is the code for an example custom Endpoint called MyPrintEndpoint
. This Endpoint prints Log Entries to Xcode’s debug console.
To use this custom Endpoint, a developer would include it when initializing their Logger:
The Logger instance will use its Endpoints’ settings to convert each Log Entry to a string, before asking the Endpoint to write
it.