https://github.com/allegro/swiftbox-logging
https://github.com/allegro/swiftbox-logging
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/allegro/swiftbox-logging
- Owner: allegro
- License: apache-2.0
- Created: 2019-07-22T13:40:56.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-20T21:46:27.000Z (over 2 years ago)
- Last Synced: 2025-04-11T23:49:17.451Z (3 months ago)
- Language: Swift
- Size: 8.79 KB
- Stars: 1
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftBoxLogging
Logging system for Swift/Vapor.
Official https://github.com/apple/swift-log package should be used instead, this package is deprecated.[](https://travis-ci.org/allegro/swiftbox-logging)


## General
### Usage
#### 1. Import
```swift
import SwiftBoxLogging
```#### 2. Bootstrap
Logging should be bootstrapped before use (it defaults to `PrintLogger`).
Bootstrap requires one parameter which is the logger factory.
Logger factory must return `Logger` from `Console/Logging` package.
```swift
Logging.bootstrap({ name in Logger2(name) })
```#### 2. Usage
Create a logger instance:
```swift
fileprivate var logger = Logging.make(#file)
```Log a message:
```swift
logger.verbose("verbose")
logger.debug("debug")
logger.info("info")
logger.warning("warning")
logger.error("error")
logger.fatal("fatal")
```### Custom Loggers
To create custom loggers your class must conform to `Logger` protocol from `Console/Logging` package.### Vapor
You can use same logging in Vapor and logging package:
```swift
private func configureLogging(_ config: inout Config, _ env: inout Environment, _ services: inout Services) {
/// Register Logger2
services.register(Logger2.self)switch env {
case .production:
config.prefer(Logger2.self, for: Logger.self)
Logging.bootstrap({ name in Logger2(name) })
default:
config.prefer(PrintLogger.self, for: Logger.self)
Logging.bootstrap({ _ in PrintLogger() })
}
}
```