• Public
  • Public/Protected
  • All


Type aliases


Ratlog: { logger: (writer: Writer<RatlogData>, ...tags: Stringable[]) => Ratlogger; stringify: (log: RatlogData) => string }

The default export is a function that creates a logger.

All it does is returning a log function bound to a writable stream or function.


const ratlog = require('ratlog')
const log = ratlog(process.stdout)

The logger can also be directly created with one or more tags:

const critical = ratlog(process.stderr, 'warn', 'critical')
critical('oh no!')
// => [warn|critical] oh no!

Alternatively a customized logger can be created using ratlog.logger() and ratlog.stringify().

This can be used to filter out logs with certain tags:

const log = ratlog.logger(log => {
  if (process.env.DEBUG || !log.tags.includes('debug')) {

Or one can only use the Ratlog logging API but skip the output format and use JSON instead:

const log = ratlog.logger(log => {

Type declaration


RatlogData: { fields: {}; message: Stringable; tags: Stringable[] }

RatlogData represents an unprocessed log as data.

Type declaration


Ratlogger: { tag: (...tags: Stringable[]) => Ratlogger }

Ratlogger is the main logging function.

Ratlogger takes a message, an object of fields and a rest of tags.

No argument is required, but the typings force you to at least provide a message. That is a good practise because an empty log line is mostly meaningless.

fields and tags are optional:

log('hey there')

If you want to add tags but no fields, you can omit the fields:

log('msg', 'mytag')

Type declaration


Stringable: string | ToString

Ratlog tries its best to get a string representation of values passed to it.

If possible values should be passed as strings directly. Otherwise Ratlog tries calling .toString() on the given value.

Errors are catched in case that fails. Logging should never fail. But it is not pretty.

null and undefined are converted to empty strings.


ToString: { toString: () => string }

ToString is automatically implemented by any object with a .toString() method.

Most JavaScript values already implement it by default, but if you have complex data types, you can create your own implementation to create a more readable representation.

Type declaration

  • toString: () => string
      • (): string
      • Returns string


Writer<T>: { write: (data: T) => void } | ((data: T) => void)

Writer is a narrow interface for the stream or function passed to the Ratlog constructor.

In practise you would mostly want to pass a stream like process.stdout but having this narrow interface allows you to easily create mock versions for testing and so on.

By implementing your own writer, you could even use Ratlog in the browser:

const log = ratlog(console.log)

Type parameters

  • T


Const ratlog

ratlog: Ratlog

The default export is a function to create a logger.

See Ratlog at the top of this document.


  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc