(macro)
conΒ·solΒ·aΒ·ble β 1) able to be comforted; 2) able to log to the Console π
Consolable is a tiny Swift Macro that injects a Logger and convenience log functions backed by OSLog.
- Per-type Logger with type-aware subsystem and category
- Optional prefix prepended to every message for that type
- Two helpers:
log(_: isError:)for instance and static contexts - Defaults to .info, uses .error when isError = true
- No file/line/function noise (
OSLogincludes that automatically)
Compatible with all Apple platforms.
Add Consolable via the Swift Package Manager π¦
- Xcode β File β Add Package Dependencies
- Enter: https://github.com/superturboryan/Consolable
- Add the Consolable library to your project target
Find out more about Consolable on the Swift Package Index π
Annotate your types with @Consolable and call log(_:, isError:)
import Consolable
let prefix = "π"
@Consolable(prefix) // Optional: set a per-type prefix
struct ThingThatNeedsLogging {
func instanceMethod() {
log("Something to log")
// -> "π Something to log" at .info
log("Something went wrong", isError: true)
// -> "π Something went wrong" at .error
}
static func staticMethod() {
log("Something else to log")
// -> "π Something else to log" at .info
}
}Custom subsystem & category
@Consolable("[Network]", subsystem: "com.your.app", category: "Helpers.Network")
final class NetworkHelper {
func fetch() {
log("Starting request")
log("Request failed", isError: true)
}
}