Skip to main content
Deno 2 is finally here 🎉️
Learn more

Papyrus-File

GitHub release (latest by date including pre-releases) GitHub commits since latest release (by SemVer) GitHub code size in bytes deno doc GitHub

A transport for Papyrus that outputs your logs to files. Rotating logs are supported.

How to use

Basic usage:

import { Papyrus } from "https://deno.land/x/papyrus/mod.ts";
import { PapyrusFile } from "https://deno.land/x/papyrus-file/mod.ts";

const logger = new Papyrus({
  transport: {
    use: new PapyrusFile
  }
});

logger.info("This is an info");

Or with rotating logs:

import { Papyrus } from "https://deno.land/x/papyrus@v1.0.0/mod.ts";
import { PapyrusFile } from "https://deno.land/x/papyrus-file/mod.ts";

const logger = new Papyrus({
  transport: {
    use: new PapyrusFile({
      maxFileSize: "2 kB",
      rotate: true,
      timeFormat: "yyyyMMdd-hhmmssSSS"
    })
  }
});

setInterval(() => {
  logger.warn("This is a warning");
}, 200);

Table of contents

Options

PFileOptions

Papyrus-File can be configured through an object that implements the interface PFileOptions. All properties are optional.

interface PFileOptions {
  maxFileSize?: string | number;
  output?: string;
  rotate?: boolean;
  timeFormat?: string;
}
Property Type Default Description
maxFileSize string | number “10 MB” When log rotation is enabled, defines when to rotate. Values in bytes (B), kilobytes (kB) and megabytes (MB) are accepted. Megabytes is the default unit.
output string ”./output.log” Relative or absolute path to the log file
rotate boolean false Enables log rotation
timeFormat string “yyyyMMdd-hhmmssSSS” Time format according to date_format_deno

Contributions

PRs are welcome!