createLogger

Gitlab
A utility function for creating tagged Consola logger instances with optional custom configuration.
Added since: v0.1.0
Last changed:
Before you start, make sure you have read the Consola documentation or at least know the basics of Consola.

Overview

createLogger() is a utility that helps create standardized, tagged logger instances using Consola. It provides a consistent way to create loggers across our libraries with proper naming and optional custom configuration, making debugging and monitoring more effective.

Anatomy

import { createLogger } from '@nobears-front-end/utils';

// Create a basic tagged logger
const logger = createLogger('MyModule');

// Create a logger with custom options
const logger = createLogger('AuthService', { 
  level: 2,
  fancy: true 
});

API Reference

createLogger()

Creates a tagged Consola logger instance with optional custom configuration.

PropDefaultType
name*
string
A tag name that identifies the logger
options
LoggerOptions
Optional configuration including Consola options and fancy mode

LoggerOptions

Extended options for the logger, allowing standard Consola options plus an optional fancy flag.

PropDefaultType
fancy
boolean
Enables fancy output for custom formatting/themes
level
number
Log level (0: silent, 1: fatal, 2: error, 3: warn, 4: log, 5: info, 6: success, 7: debug, 8: trace)
formatOptions
ConsolaFormatOptions
Formatting options for log messages
transport
LogType | LogObject | LogFn
Custom transport for log messages

Examples

import { createLogger } from '@nobears-front-end/utils';

const logger = createLogger('MyModule');

logger.info('Application started');
logger.warn('Deprecated feature used');
logger.error('Something went wrong');
logger.debug('Debug information');

Changelog