{"id":"mark-marks/sapphire-logging","name":"sapphire-logging","scope":"mark-marks","platform":"roblox","description":"Mirrored from the Wally registry.","version":"0.1.2","latest":"0.1.2","versions":["0.1.2"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"red-blox/signal":{"version":"^2.0.2","alias":"signal"}},"integrity":"14ef1dc625e23fcf6db1e8ca75d0fe0c158cc5f5cffb8d09dd3a0dcc6107302a","likes":0,"downloads":0,"install":"forest install mark-marks/sapphire-logging","url":"https://forest.dev/p/roblox/mark-marks/sapphire-logging","files":"https://api.forest.dev/ai/package/roblox/mark-marks/sapphire-logging/files","readme":"# sapphire-logging\r\nA simple logging libary with a logbook for [Mark-Marks/sapphire](https://github.com/Mark-Marks/sapphire)\r\n\r\n# Installation\r\n1. Install it with wally\r\n```toml\r\n[dependencies]\r\nsapphire_logging = \"mark-marks/sapphire-logging@LATEST\"\r\n```\r\n2. `wally install`\r\n3. Extend sapphire with it\r\n```luau\r\nlocal sapphire_logging = require(\"@pkg/sapphire_logging\")\r\n\r\nsapphire\r\n    :use(sapphire_logging)\r\n```\r\n\r\n# API\r\n\r\n## Types\r\n\r\n### signal<T...>\r\n```luau\r\ntype signal<T...> = {\r\n    Root: signal_node<T...>?,\r\n\r\n    Connect: (self: signal<T...>, Callback: (T...) -> ()) -> () -> (),\r\n    Wait: (self: signal<T...>) -> T...,\r\n    Once: (self: signal<T...>, Callback: (T...) -> ()) -> () -> (),\r\n    Fire: (self: signal<T...>, T...) -> (),\r\n    DisconnectAll: (self: signal<T...>) -> (),\r\n}\r\n```\r\n\r\n### log_type\r\n```luau\r\ntype log_type = \"info\" | \"debug\" | \"warn\" | \"error\" | \"fatal\"\r\n```\r\n\r\n### log\r\n```luau\r\ntype log = {\r\n    --- Timestamps representing when the log took place\r\n    timestamp: {\r\n        --- CPU time at the time of log\r\n        clock: number,\r\n        --- Seconds passed since the start of the UNIX epoch at the time of log\r\n        unix: number,\r\n    },\r\n    --- Type of the log\r\n    type: log_type,\r\n    --- Message passed to the log\r\n    msg: string,\r\n    --- Full traceback of all function calls leading to this log\r\n    trace: string,\r\n}\r\n```\r\n\r\n### sink\r\n```luau\r\ntype sink = (log) -> ()\r\n```\r\n\r\n### logger\r\n```luau\r\ntype logger = {\r\n    _debug: boolean,\r\n    msg_out: signal<log>,\r\n    logbook: { log },\r\n\r\n    new: (debug: boolean?) -> logger,\r\n    write: (self: logger, log_type: log_type, msg: string, trace: string) -> log,\r\n    debug: (self: logger, msg: string) -> log?,\r\n    warn: (self: logger, msg: string) -> log,\r\n    error: (self: logger, msg: string) -> log,\r\n    fatal: (self: logger, msg: string) -> (),\r\n\r\n    connect_sink: (self: logger, sink: sink) -> () -> (),\r\n}\r\n```\r\n\r\n## Exports\r\n\r\n### .identifier\r\nReadonly, extension identifier required by sapphire.\r\n```luau\r\ntype identifier = string\r\n```\r\n\r\n### .methods\r\nReadonly\r\n```luau\r\ntype methods = {}\r\n```\r\n\r\n### .cache\r\nReadonly, cache for `sapphire_logging.get()`\r\n```luau\r\ntype cache = { [string]: logger }\r\n```\r\n\r\n### .default\r\nA default, uncached logger\r\n```luau\r\ntype default = logger\r\n```\r\n\r\n### .sinks\r\nDefault sinks, connectable with `logger:connect_sink()`\r\n```luau\r\ntype sinks = {\r\n    --- Roblox logging sink.\r\n    roblox: sink,\r\n}\r\n```\r\n\r\n## Registered Methods\r\n\r\nN/A\r\n\r\n## Functions\r\n\r\n### .extensions()\r\nReadonly, required by sapphire for extension startup.\r\n```luau\r\n() -> ()\r\n```\r\n\r\n### .get()\r\nGets an existing cached logger or creates a new one.\r\n```luau\r\n(\r\n    identifier: string,\r\n    debug: boolean?, -- Only applied if the logger doesn't exist\r\n) -> logger\r\n```\r\n\r\n## logger\r\n\r\n### ._debug\r\nReadonly - log debug messages?\r\n```luau\r\ntype _debug = boolean\r\n```\r\n\r\n### .msg_out\r\nReadonly - on log signal, connect with `:connect_sink()`\r\n```luau\r\ntype msg_out = signal<log>\r\n```\r\n\r\n### .logbook\r\nReadonly logbook of all logs that happened\r\n```luau\r\ntype logbook = { log }\r\n```\r\n\r\n### .new()\r\nCreates a new logger.\r\n```luau\r\n(\r\n    debug: boolean? --  Should debug messages be logged? Defaults to false\r\n) -> logger\r\n```\r\n\r\n### :write()\r\nWrites a message to the logger.\r\nPrefer to use the logging methods instead of this.\r\n```luau\r\n(\r\n    self: logger,\r\n    log_type: log_type,\r\n    msg: string,\r\n    trace: string -- Full traceback of all function calls leading to this\r\n) -> log\r\n```\r\n\r\n### :info()\r\nWrites an `info` to the logger.\r\n```luau\r\n(\r\n    self: logger,\r\n    msg: string\r\n) -> log\r\n```\r\n\r\n### :debug()\r\nWrites a `debug` to the logger, IF logger is in debug mode.\r\n```luau\r\n(\r\n    self: logger,\r\n    msg: string\r\n) -> log?\r\n```\r\n\r\n### :warn()\r\nWrites a `warn` to the logger.\r\n```luau\r\n(\r\n    self: logger,\r\n    msg: string\r\n) -> log\r\n```\r\n\r\n### :error()\r\nWrites an `error` to the logger, continues execution.\r\n```luau\r\n(\r\n    self: logger,\r\n    msg: string\r\n) -> log\r\n```\r\n\r\n### :fatal()\r\nKills the current thread after writing a `fatal` to the logger.\r\n```luau\r\n(\r\n    self: logger,\r\n    msg: string\r\n)\r\n```\r\n\r\n### :connect_sink()\r\nConnects the given sink to the loggers `msg_out` signal.\r\nReturns a disconnect function.\r\n```luau\r\n(\r\n    self: logger,\r\n    sink: sink\r\n) -> () -> ()\r\n```\r\n","readmeTruncated":false}