BudgetBuddyDE

@budgetbuddyde/logger

CI Build StatusNPM VersionNPM LicenseNPM Last Update

A collection of utility functions, configurations, and formatters for Winston loggers used within the BudgetBuddy project.

Features

  • Log Level Utilities: Helper functions for parsing and validating log levels from environment variables
  • Console Format Builder: Pre-configured Winston formatters for consistent console output
  • Level Padding: Formatting for uniform level output in logs
  • Level Configuration: Standardized log level configuration with colors for the entire project
  • TypeScript Support: Fully typed with comprehensive type definitions
  • Winston Integration: Seamless integration with Winston for all services and apps

Installation

npm install @budgetbuddyde/logger

Quick Start

Log Level from Environment Variables

import { getLogLevel } from '@budgetbuddyde/logger';
 
const logLevel = getLogLevel(process.env.LOG_LEVEL); // 'info', 'debug', 'warn', etc.

Winston Logger with Custom Format

import { createLogger, format, transports } from 'winston';
import { buildConsoleFormat, padLevel, LevelConfig } from '@budgetbuddyde/logger';
 
const logger = createLogger({
  levels: LevelConfig.levels,
  level: getLogLevel(process.env.LOG_LEVEL),
  format: format.combine(
    format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
    format.splat(),
    padLevel(5), // Pads level to 5 characters
    format.colorize({ level: true, colors: LevelConfig.colors }),
    buildConsoleFormat('MyService', false) // Show service name and meta
  ),
  transports: [new transports.Console()],
});
 
logger.info('Application started');
logger.warn('This is a warning');
logger.error('An error occurred');

Usage in the Project

The logger package is used across all services (Backend, Auth-Service) and apps (WebApp) in the BudgetBuddy project to ensure consistent logging configuration and formatting.

In the Backend Service

import { createLogger, format } from 'winston';
import { buildConsoleFormat, padLevel, LevelConfig } from '@budgetbuddyde/logger';
 
export const logger = createLogger({
  levels: LevelConfig.levels,
  level: config.log.level,
  format: format.combine(
    format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
    format.splat(),
    padLevel(5),
    format.colorize({ level: true, colors: LevelConfig.colors }),
    buildConsoleFormat(config.service, config.log.hideMeta)
  ),
  transports: config.log.transports,
});

In the WebApp

For the WebApp, a simplified version using direct createLogger from the package is used (if available), or Winston is configured directly.

Publishing

The package is published automatically when changes are made to the main branch. Publishing takes place via Concourse CI within the bb-logger workflow.

On this page