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.
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
LXEndpoint protocol defines the following required properties:
||The minimum Priority Level a Log Entry must meet to be accepted by this Endpoint|
||The formatter used by this Endpoint to serialize a Log Entry’s
||The formatter used by this Endpoint to serialize each Log Entry to a string|
||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.
||Writes a serialized Log Entry string to the final destination this Endpoint represents|
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: