@seda-protocol/rotating-file-logger
v2.2.0
Published
Effect-based rotating file logger. Writes logs to date-named files (e.g. `yyyy-MM-dd.log`), batches writes, and prunes old files.
Readme
@seda-protocol/rotating-file-logger
Effect-based rotating file logger. Writes logs to date-named files (e.g. yyyy-MM-dd.log), batches writes, and prunes old files.
Usage
Wrap your program with provideRotatingFileLogger to replace the default logger with one that logs to both console (with colors) and rotating files:
import { Effect } from "effect";
import { provideRotatingFileLogger } from "@seda-protocol/rotating-file-logger";
const program = Effect.log("Hello");
Effect.runPromise(program.pipe(provideRotatingFileLogger));For custom configuration, use provideRotatingFileLoggerWithOptions:
import { Effect } from "effect";
import { provideRotatingFileLoggerWithOptions } from "@seda-protocol/rotating-file-logger";
// JSON to stdout only, no files (e.g. containerized deployment)
const program = Effect.log("Hello");
Effect.runPromise(
program.pipe(
provideRotatingFileLoggerWithOptions({
stdoutFormat: "json",
fileLogging: false,
}),
),
);Configuration
| Env var | Default | Description |
|----------------------|-----------|-----------------------------------------------------------------------------|
| LOG_LEVEL | Info | Minimum log level (None, Fatal, Error, Warning, Info, Debug, Trace) |
| LOG_DIR | logs | Directory for log files |
| LOG_MAX_FILES | 14 | Max number of date-based log files to keep |
| LOG_STDOUT_FORMAT | pretty | Stdout format: pretty (colored) or json (one JSON object per line) |
| LOG_FILE_ENABLED | true | When false, disables rotating file logging entirely |
Programmatic options passed to provideRotatingFileLoggerWithOptions override environment variables:
| Option | Default | Description |
|-----------------|-----------|--------------------------------------------------|
| stdoutFormat | env | Stdout format: pretty or json |
| fileLogging | env | When false, skips file I/O and rotation |
| logLevel | env | Minimum log level |
| batchWindow | 1 second | Duration to batch file log writes |
| mapOutput | none | Transform final log strings before output. This is also applied to JSON output, so preserve valid JSON if downstream parsers expect it |
Log files are named by date (e.g. 2025-03-17.log). When the date changes, a new file is created and files older than LOG_MAX_FILES are removed. A small config file (rotating-logger.json) in the log directory tracks active files.
