A Swifty GrayLog Framework, supporting GELF additional fields and offline log queuing out of the box.
||iOS >= 10.1
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate SGLog into your Xcode project, specify it in your
Swift Package Manager
Support for the Swift Package Manager is planned to be added later this year.
SGLog needs a Graylog GELF HTTP input to send the logs to.
Whenever the graylog server is not reachable, logs are queued and stored to disk and are posted the next time a log is send successfully.
SGLog has a couple of log functions (one for each syslog level) that can be called after a url is set. The minimum variable that must be provided is the a message string. Optionally a full message can be added, as well as additional fields.
- SGLog.emergency("emergency log message")
- SGLog.alert("alert log message")
- SGLog.critical("critical log message")
- SGLog.error("error log message")
- SGLog.warning("warning log message")
- SGLog.notice("notice log message")
- SGLog.info("info log message")
- SGLog.debug("debug log message")
The full message is a string containing more detailed information about the logged message. The example at the bottom shows how these can be used.
SGLog supports GELF additional fields out of the box.
Allowed characters in field keys are any word character (letter, number, underscore), dashes and dots. The verifying regular expression is:
^[\w\.\-]*$. Key can not be
See the example below to see how additional fields can be used with the log functions.
// import the SGLog framework
// Setup SGLog Graylog URL
// Set the host (optional, if not defined it is set to "SGLog")
// Create some (optional) additional fields
let clientAF = AdditionalField(key: "_client", value: "Log test client")
let clientVersionAF = AdditionalField(key: "_clientVersion", value: "1.0")
let additionalFields = [clientAF, clientVersionAF]
// Create a message and full_message
let message = "Test Log Message"
let fullMessage = "A longer message containing more info about the stuff being logged"
// Send the log to the graylog server
SGLog.info(message, fullMessage: fullMessage, additionalFields: additionalFields)