Sprintf Plugin

Sprintf Plugin Browser Server

NPM Version

Plugin Source

The sprintf plugin provides printf-style string formatting support using sprintf-js. It allows you to format your log messages using familiar printf-style placeholders if a logging library does not support this behavior.

WARNING

LogLayer does not allow passing items that are not strings, booleans, or numbers into message methods like info, error, etc. It is recommended to only use string / boolean / number specifiers in your format strings.

Installation

bash

npm install @loglayer/plugin-sprintf

bash

yarn add @loglayer/plugin-sprintf

bash

pnpm add @loglayer/plugin-sprintf

Usage

typescript

import { LogLayer, ConsoleTransport } from 'loglayer'
import { sprintfPlugin } from '@loglayer/plugin-sprintf'

const log = new LogLayer({
  transport: new ConsoleTransport({
    logger: console
  }),
  plugins: [
    sprintfPlugin()
  ]
})

// Example usage
log.info("Hello %s!", "world")
// Output: Hello world!

log.info("Number: %d", 42)
// Output: Number: 42

Changelog

View the changelog here.