Skip to content

superturboryan/Consolable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@Consolable

(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.

Features

  • 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 (OSLog includes that automatically)

Compatibility


Compatible with all Apple platforms.

Installation

Add Consolable via the Swift Package Manager πŸ“¦

Find out more about Consolable on the Swift Package Index πŸ“‹

How to use

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)
    }
}