{"id":"flipbook-labs/archivist","name":"archivist","scope":"flipbook-labs","platform":"roblox","description":"Mirrored from the Wally registry.","version":"0.3.1","latest":"0.3.1","versions":["0.1.0","0.2.0","0.3.0","0.3.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"b5c218aa19a14c7578df41c3cdb863b7d366fa2fbc4f63d86ccf790a52cd172f","likes":0,"downloads":0,"install":"forest install flipbook-labs/archivist","url":"https://forest.dev/p/roblox/flipbook-labs/archivist","files":"https://api.forest.dev/ai/package/roblox/flipbook-labs/archivist/files","readme":"# Archivist\n\nArchivist is a structured logging library for Luau that runs on both [Lute](https://github.com/luau-lang/lute) and Roblox. Each log call produces a record that sinks send to the console, a file, or your own callback. Archivist is pre-release, and its API may change before v1.\n\n## Install\n\nFor Roblox, with Wally:\n\n```toml\n[dependencies]\nArchivist = \"flipbook-labs/archivist@0.3.1\"\n```\n\nFor Lute, add this to the `dependencies` table in `pkg.luau`, then run `lute pkg install --vendor`:\n\n```luau\n[\"archivist\"] = {\n\trev = \"v0.3.1\",\n\tsourceKind = \"github\",\n\tsource = \"https://github.com/flipbook-labs/archivist\",\n},\n```\n\nLute projects also need Lute `1.0.1-nightly.20261117` or newer, and `lpm = \"./.lpm\"` in the `aliases` table of `.config.luau`. Archivist requires its dependencies through that alias.\n\n## Use\n\n```luau\nlocal Archivist = require(\"@pkg/Archivist\")\n\nlocal logger = Archivist.createLogger(\"MyModule\")\nlogger.info(\"loaded\", 3, \"stories\")\n```\n\nOn Lute, the console prints `[info] loaded 3 stories`, and you require the vendored copy as `@lpm/archivist@v0.3.1` instead of `@pkg/Archivist`.\n\n`Archivist.getLogger(name)` returns the same logger for a given name, so modules can share one configured logger. Later calls with that name ignore their options.\n\n## Levels\n\nThe levels, in ascending order, are `trace`, `debug`, `info`, `warn`, and `err`. A logger drops records below its minimum level. The minimum comes from the first of these that is set: the `level` option, the `LOG_LEVEL` environment variable on Lute, `_G.LOG_LEVEL` on Roblox, and then `info`.\n\nThe `level` option takes the capitalized name, as in `\"Trace\"`:\n\n```luau\nlocal verbose = Archivist.createLogger(\"MyModule\", { level = \"Trace\" })\n```\n\n## Child loggers\n\n`logger.child(name, fields)` returns a logger that copies its parent's sinks, level, and mode. Its name joins the parent's name with `/`, and its fields go on every record:\n\n```luau\nlocal request = logger.child(\"requests\", { requestId = \"abc123\" })\nrequest.info(\"handling request\")\n```\n\n## Sinks\n\nWithout a `sinks` option, a logger writes to one console sink. Pass `sinks` to choose the destinations:\n\n```luau\nlocal logger = Archivist.createLogger(\"App\", {\n\tsinks = {\n\t\tArchivist.createConsoleSink(),\n\t\tArchivist.createCallbackSink(function(record)\n\t\t\tprint(record.level, record.name)\n\t\tend),\n\t},\n})\n```\n\n- `createCallbackSink(callback)` calls `callback` with each record, one at a time, even in prod mode.\n- `createFileSink({ path })` appends one JSON object per line to a file. It is Lute only, and it errors on Roblox.\n- `createTransportSink({ batchSize, send })` buffers records and calls `send` with each batch. `batchSize` defaults to 50. `send` uses your own HTTP client.\n\n## Formatters\n\nThe console sink formats each record as `[level] message`. The built-in middleware adds logger names or timestamps to that line:\n\n```luau\nlocal logger = Archivist.createLogger(\"MyModule\", {\n\tmiddleware = {\n\t\tArchivist.middleware.name,\n\t\tArchivist.middleware.timestamp,\n\t},\n})\n```\n\nMiddleware runs in the order listed. Each function receives the formatted line and a context table, and returns the line to print. The `middleware` option applies only when Archivist creates the console sink. With your own `sinks`, put middleware on a formatter instead:\n\n```luau\nlocal formatter = Archivist.createPrettyFormatter({\n\tmiddleware = { Archivist.middleware.name },\n})\nlocal logger = Archivist.createLogger(\"MyModule\", {\n\tsinks = { Archivist.createConsoleSink({ formatter = formatter }) },\n})\n```\n\n`createJsonFormatter()` writes one JSON object per line. File sinks use it by default.\n\n## Prod mode\n\nLoggers default to dev mode, where each call writes right away, like `print`. Set `mode = \"Prod\"` to queue records and write each sink once per batch. Call `logger.flush()` before a short-lived program exits, so queued records reach the sinks.\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## License\n\nMIT.\n","readmeTruncated":false}