Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juanjoarreola/logg
Logger for swift
https://github.com/juanjoarreola/logg
logging swift
Last synced: about 1 month ago
JSON representation
Logger for swift
- Host: GitHub
- URL: https://github.com/juanjoarreola/logg
- Owner: JuanjoArreola
- License: mit
- Created: 2017-04-19T01:01:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-03T15:26:40.000Z (over 4 years ago)
- Last Synced: 2024-10-30T17:14:54.435Z (about 2 months ago)
- Topics: logging, swift
- Language: Swift
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A logging framework for swift
![Cocoapods](https://img.shields.io/cocoapods/v/Logg.svg)
![Platform](https://img.shields.io/cocoapods/p/Logg.svg)
![License](https://img.shields.io/cocoapods/l/Logg.svg)## Usage
```swift
logger.info("Current loggers: \(Log.loggers)")
logger.debug("Using formatter: \(Log.loggers.first!.formatter)")
logger.error(TestError.invalid)
logger.fault("some error")
```
###### Prints:
```
04-21 13:04:30.040 LoggTests.swift testFileLogger() [14] ❕ Info: Current loggers: [Logg.ConsoleLogger]
04-21 13:04:30.041 LoggTests.swift testFileLogger() [15] 🐛 Debug: Using formatter: Logg.DefaultFormatter
04-21 13:04:30.041 LoggTests.swift testFileLogger() [16] ❗ Error: invalid
04-21 13:04:30.041 LoggTests.swift testFileLogger() [17] ‼️ Fault: some error
```## Configuration
`Log` is the class that dispatch the messages to all the loggers, you can configure this loggers modifying the loggers static property:
```swift
if debug {
Log.loggers = [ConsoleLogger()]
} else {
Log.loggers = [CustomLogger(level: [.error, .severe])]
}
```Each logger has a property named level that you can customize:
```swift
let consoleLogger = Log.loggers.first
consoleLogger?.level = [.debug, .warning]
```The level is an `OptionSet` with 4 basic values: `debug`, `warning`, `error`, `severe` and additionally `all` and `none`
## Logger
You can create and register your own loggers, just implement the `Logger` protocol and add an instance to the `loggers` static property of the `Log` class. The `Logger` protocol defines a couple of properties, `level` and `formatter`, and four functions: `debug, warn, error` and `severe` that correspond to the log levels
## Formatter
You can create your own formatter and use it with the loggers you want, just create a class that implements the `Formatter` protocol and assign it to the logger
```swift
let consoleLogger = Log.loggers.first
consoleLogger?.formatter = CustomFormatter()
```