Contents

superturboryan/consolable

> *(macro)*

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 πŸ“¦

  • 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 πŸ“‹

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

Package Metadata

Repository: superturboryan/consolable

Default branch: main

README: README.md