Go to file
Leif 9d3c974f52 Remove sneaky import 2023-03-29 17:48:26 -06:00
.github/workflows Create docc.yml 2023-02-16 17:17:28 -07:00
Sources/Scribe Remove o and plugins (#8) 2023-03-29 17:38:21 -06:00
Tests/ScribeTests Remove sneaky import 2023-03-29 17:48:26 -06:00
.gitignore Update Plugin to 2.0.0 for Fork async (#7) 2023-02-17 19:33:29 -07:00
LICENSE Create LICENSE 2023-01-30 19:58:06 -07:00
Package.swift Remove o from package 2023-03-29 17:44:30 -06:00
README.md Remove output parameter from ScribePlugin handle (#3) 2023-02-01 18:02:00 -07:00

README.md

Scribe

📜 Logging all events

Scribe is a flexible logging library for Swift, designed to make logging easy and efficient. It provides a centralized system for logging messages and events within your application, and supports multiple logging outputs and plugins to extend its capabilities to meet your needs. Scribe integrates with swift-log for console logging, making it a versatile solution for all your logging requirements.

Usage

Creating a ScribePlugin

To create a Scribe plugin, you need to create a struct or class that conforms to the ScribePlugin protocol and implement its requirements. Here is an example of a simple plugin that increments a count for each log:

class CountPlugin: ScribePlugin {
    static let shared = CountPlugin()

    var count: Int = 0

    private init() {}

    func handle(value: Scribe.PluginPayload) async throws {
        count += 1
    }
}

Registering plugins to Scribe

Once you have created your Scribe Plugin, you just need to register it with your Scribe object. There are two ways to do this:

  1. Pass the plugin to the plugins parameter when creating the Scribe object:
let scribe = Scribe(
    label: "test.count",
    plugins: [
        CountPlugin.shared
    ]
)
  1. Call scribe.register(plugin:) to add the plugin to an existing Scribe object:
let scribe = Scribe(label: "test.count")

scribe.register(plugin: CountPlugin.shared)

Logging to Scribe

Scribe uses swift-log for logging, so the functions are similar in usage. To log a message with Scribe, simply call one of the logging functions, such as debug:

scribe.debug("Test")

Log Levels

Scribe supports the following log levels:

  • trace
  • debug
  • info
  • notice
  • warning
  • error
  • critical

Choose the appropriate log level depending on the importance and urgency of the message you are logging.