Sprintf Plugin Browser Server
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-sprintfbash
yarn add @loglayer/plugin-sprintfbash
pnpm add @loglayer/plugin-sprintfUsage
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: 42Changelog
View the changelog here.
