UNPKG

@inkdropapp/logger

Version:
75 lines (50 loc) 2 kB
# @inkdropapp/logger A lightweight logging library for Inkdrop that provides structured logging with multiple log levels. Built on top of the popular `debug` package, it offers colored output and environment-aware configuration. ## Features - **Multiple log levels**: debug, info, warn, error - **Colored output**: Automatically enabled in browsers and configurable in Node.js - **Namespace support**: Create custom loggers with specific namespaces - **Environment detection**: Smart color enabling based on environment - **Console method binding**: Each log level uses the appropriate console method ## Installation ```bash npm install @inkdropapp/logger ``` ## Usage ### Basic Usage ```js import debug from 'debug' import logger from '@inkdropapp/logger' // Enable debug output for your namespace debug.enable('app:*') // Use the default logger logger.debug('Starting Inkdrop..') logger.info('Application initialized') logger.warn('This is a warning') logger.error('An error occurred') ``` ### Custom Logger ```js import debug from 'debug' import { createLogger } from '@inkdropapp/logger' debug.enable('mymodule:*') const logger = createLogger('mymodule') logger.debug('Debug message from custom logger') ``` ### Disable Colors ```js import { createLogger } from '@inkdropapp/logger' const logger = createLogger('app', false) // Colors disabled ``` ## API ### `createLogger(name: string, colorEnabled?: boolean)` Creates a new logger instance with the specified namespace. - `name`: The namespace for the logger (e.g., 'app', 'mymodule') - `colorEnabled`: Optional boolean to enable/disable colors (defaults to environment detection) Returns an object with four logging methods: - `debug(message)`: Debug level logging - `info(message)`: Info level logging - `warn(message)`: Warning level logging - `error(message)`: Error level logging ### Default Export The package exports a default logger instance configured with namespace 'app' and automatic color detection.