Console Transport
The simplest integration is with the built-in console
object, which is available in both Node.js and browser environments.
Installation
No additional packages needed beyond the core loglayer
package:
sh
npm i loglayer
sh
pnpm add loglayer
sh
yarn add loglayer
Setup
typescript
import { LogLayer, ConsoleTransport } from 'loglayer'
const log = new LogLayer({
transport: new ConsoleTransport({
logger: console,
// Optional: control where object data appears in log messages
appendObjectData: false // default: false - object data appears first
})
})
Configuration Options
appendObjectData
Controls where object data (metadata, context, errors) appears in the log messages:
false
(default): Object data appears as the first parametertrue
: Object data appears as the last parameter
Example with appendObjectData: false
(default):
typescript
log.withMetadata({ user: 'john' }).info('User logged in');
// console.info({ user: 'john' }, 'User logged in')
Example with appendObjectData: true
:
typescript
log.withMetadata({ user: 'john' }).info('User logged in');
// console.info('User logged in', { user: 'john' })
Log Level Mapping
LogLayer | Console |
---|---|
trace | debug |
debug | debug |
info | info |
warn | warn |
error | error |
fatal | error |