@loglayer/plugin-sprintf
v1.0.1
Published
sprintf plugin for loglayer.
Downloads
375
Maintainers
Readme
Sprintf Plugin for LogLayer
The sprintf plugin for loglayer provides printf-style string formatting support using sprintf-js.
It allows you to format your log messages using familiar printf-style placeholders if a transport does not support this behavior.
Disclaimer
- LogLayer does not allow passing items that are not strings or numbers into message methods like
info
,error
, etc, and would recommend that only string and number specifiers be used. - Not all logging libraries support multiple parameters in a message method, so this plugin is useful for those that do.
Installation
npm install @loglayer/plugin-sprintf
Usage
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
Documentation
For more details, visit https://loglayer.dev/plugins/sprintf