Skip to main content

Built and signed on GitHub Actions

Simple logging library with zero dependencies for Deno/Node.js/Bun/browsers

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 weeks ago (0.8.0)
interface TextFormatterOptions

The various options for the built-in text formatters.

Properties

optional
timestamp:
"date-time-timezone"
| "date-time-tz"
| "date-time"
| "time-timezone"
| "time-tz"
| "time"
| "date"
| "rfc3339"
| ((ts: number) => string)

The timestamp format. This can be one of the following:

  • "date-time-timezone": The date and time with the full timezone offset (e.g., "2023-11-14 22:13:20.000 +00:00").
  • "date-time-tz": The date and time with the short timezone offset (e.g., "2023-11-14 22:13:20.000 +00").
  • "date-time": The date and time without the timezone offset (e.g., "2023-11-14 22:13:20.000").
  • "time-timezone": The time with the full timezone offset but without the date (e.g., "22:13:20.000 +00:00").
  • "time-tz": The time with the short timezone offset but without the date (e.g., "22:13:20.000 +00").
  • "time": The time without the date or timezone offset (e.g., "22:13:20.000").
  • "date": The date without the time or timezone offset (e.g., "2023-11-14").
  • "rfc3339": The date and time in RFC 3339 format (e.g., "2023-11-14T22:13:20.000Z").

Alternatively, this can be a function that accepts a timestamp and returns a string.

The default is "date-time-timezone".

optional
level:
"ABBR"
| "FULL"
| "L"
| "abbr"
| "full"
| "l"
| ((level: LogLevel) => string)

The log level format. This can be one of the following:

  • "ABBR": The log level abbreviation in uppercase (e.g., "INF").
  • "FULL": The full log level name in uppercase (e.g., "INFO").
  • "L": The first letter of the log level in uppercase (e.g., "I").
  • "abbr": The log level abbreviation in lowercase (e.g., "inf").
  • "full": The full log level name in lowercase (e.g., "info").
  • "l": The first letter of the log level in lowercase (e.g., "i").

Alternatively, this can be a function that accepts a log level and returns a string.

The default is "ABBR".

optional
category: string | ((category: readonly string[]) => string)

The separator between category names. For example, if the separator is "·", the category ["a", "b", "c"] will be formatted as "a·b·c". The default separator is "·".

If this is a function, it will be called with the category array and should return a string, which will be used for rendering the category.

optional
value: (value: unknown) => string

The format of the embedded values.

A function that renders a value to a string. This function is used to render the values in the log record. The default is util.inspect() in Node.js/Bun and Deno.inspect() in Deno.

optional
format: (values: FormattedValues) => string

How those formatted parts are concatenated.

A function that formats the log record. This function is called with the formatted values and should return a string. Note that the formatted should not include a newline character at the end.

By default, this is a function that formats the log record as follows:

2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!

Add Package

deno add jsr:@logtape/logtape

Import symbol

import { type TextFormatterOptions } from "@logtape/logtape";

---- OR ----

Import directly with a jsr specifier

import { type TextFormatterOptions } from "jsr:@logtape/logtape";

Add Package

npx jsr add @logtape/logtape

Import symbol

import { type TextFormatterOptions } from "@logtape/logtape";

Add Package

yarn dlx jsr add @logtape/logtape

Import symbol

import { type TextFormatterOptions } from "@logtape/logtape";

Add Package

pnpm dlx jsr add @logtape/logtape

Import symbol

import { type TextFormatterOptions } from "@logtape/logtape";

Add Package

bunx jsr add @logtape/logtape

Import symbol

import { type TextFormatterOptions } from "@logtape/logtape";