Pino-based logger service for the Famir platform.
This package provides a shared logging layer built on top of Pino library.
The package is structured as:
src/logger.ts — Common types and definitions.src/logger.schemas.ts — Various validation schemas.src/pino-logger.ts — Pino-based logger implementation.src/index.ts - Package public exports.And exposes the following dependencies:
Logger via LOGGER tokennpm install @famir/logger
Expects the following configuration variables:
LOGGER_LOG_LEVEL - logging level for the application, default: infoAvailable LOGGER_LOG_LEVEL values: trace, debug, info, warn, error and fatal.
Example:
LOGGER_LOG_LEVEL="debug"
The logger also supports runtime settings:
appName - application name to be used, default: unknownExample:
{
appName: 'console',
}
Example:
import { DIContainer } from '@famir/common'
import { AjvValidator } from '@famir/validator'
import { EnvConfig } from '@famir/config'
import { PinoLogger } from '@famir/logger'
// Get the global DI container instance.
const container = DIContainer.getInstance()
// Register dependencies:
AjvValidator.register(container)
EnvConfig.register(container)
PinoLogger.register(container, { appName: 'console' })
Example:
import { DIContainer } from '@famir/common'
import { LOGGER, Logger } from '@famir/domain'
// Get the global DI container instance.
const container = DIContainer.getInstance()
// Resolve dependency:
const logger = container.resolve<Logger>(LOGGER)
Example:
import { serializeError } from '@famir/common'
logger.debug('Application started')
logger.info('Session created', {
data: {
id: 'client-a3a7',
lastIp: '127.0.0.1',
secret: 'fd2c0acd',
},
})
const error = new Error(`Database not connected`)
logger.error('Failed to start application', {
error: serializeError(error),
})
The logger supports an optional custom transport implementation via LOGGER_TRANSPORT token.
This is useful when you want to send logs to a custom stream or backend. The default behavior is to use the standard Pino output.
Example:
import { LOGGER_TRANSPORT, LoggerTransport } from '@famir/logger'
const loggerTransport = PinoLogger.createTransport({
target: 'pino-roll',
options: { ... },
})
container.registerSingleton<LoggerTransport>(LOGGER_TRANSPORT, () => loggerTransport)