Update message output in README
Welcome to LoggingSlack – a logging backend for SwiftLog that sends critical log messages to Slack.
LoggingSlack uses Incoming Webhooks to send log messages to a Slack channel.
Once you’ve setup Incoming Webhooks, you should have a webhook URL that you can use to configure LoggingSlack.
LoggingSlack is intended to be used as a secondary logging backend to send critical log messages directly to Slack.
You can use SwiftLog’s MultiplexLogHandler to setup LoggingSlack with another logging backend.
MultiplexLogHandler
import Logging import LoggingSlack let webhookURL = URL(string: "https://hooks.slack.com/services/T1MGQL1L8/RM2LE5QLF/YH036NhldqitdR1lVd5NLS6z")! LoggingSystem.bootstrap { label in MultiplexLogHandler([ // Setup SlackLogHandler with a webhook URL SlackLogHandler(label: label, webhookURL: webhookURL), // Setup the standard logging backend to enable console logging StreamLogHandler.standardOutput(label: label) ]) }
You can now use SwiftLog as usual and critical log messages are sent directly to Slack.
import Logging let logger = Logger(label: "com.example.ExampleApp.main") logger.critical("Something went wrong!")
The logger will output a Slack message and a console message since both logging backends were setup.
2020-02-15T19:30:00-0800 critical: Something went wrong!
Only critical log level messages are sent to Slack by default.
critical
You can adjust the log level threshold by changing the globalLogLevelThreshold static property on SlackLogHandler.
globalLogLevelThreshold
SlackLogHandler
For example, this will configure LoggingSlack to send all error log level and above messages to Slack.
error
SlackLogHandler.globalLogLevelThreshold = .error
Visit the online API reference for full documentation of the public API.
LoggingSlack requires Xcode 11 or a Swift 5.1 toolchain with the Swift Package Manager.
Add the LoggingSlack package as a dependency to your Package.swift file.
Package.swift
.package(url: "https://github.com/wlisac/swift-log-slack.git", from: "0.1.0")
Add LoggingSlack to your target’s dependencies.
.target(name: "Example", dependencies: ["LoggingSlack"])
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
LoggingSlack
Welcome to LoggingSlack – a logging backend for SwiftLog that sends critical log messages to Slack.
Usage
Setup Incoming Webhooks
LoggingSlack uses Incoming Webhooks to send log messages to a Slack channel.
Once you’ve setup Incoming Webhooks, you should have a webhook URL that you can use to configure LoggingSlack.
Bootstrap SwiftLog
LoggingSlack is intended to be used as a secondary logging backend to send critical log messages directly to Slack.
You can use SwiftLog’s
MultiplexLogHandler
to setup LoggingSlack with another logging backend.Using a Logger
You can now use SwiftLog as usual and critical log messages are sent directly to Slack.
Logger Output
The logger will output a Slack message and a console message since both logging backends were setup.
Log Level Threshold
Only
critical
log level messages are sent to Slack by default.You can adjust the log level threshold by changing the
globalLogLevelThreshold
static property onSlackLogHandler
.For example, this will configure LoggingSlack to send all
error
log level and above messages to Slack.API Documentation
Visit the online API reference for full documentation of the public API.
Installation
LoggingSlack requires Xcode 11 or a Swift 5.1 toolchain with the Swift Package Manager.
Swift Package Manager
Add the LoggingSlack package as a dependency to your
Package.swift
file.Add LoggingSlack to your target’s dependencies.