Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@milandadhaniya/tiny-logger-js

milandadhaniya178MIT1.0.3TypeScript support: included

A tiny logger for both Node.js and browser environments, with configurable log levels and console output methods.

logger, tiny-logger, console, debug, typescript, browser, nodejs, log-levels

readme

@milandadhaniya/tiny-logger-js

A tiny, extensible logger for both browser and Node.js environments, written in TypeScript.

Installation

npm install @milandadhaniya/tiny-logger-js

Usage

import logger, { TinyLogger, LoggerConfig } from '@milandadhaniya/tiny-logger-js';

// Using default logger instance
logger.log({ title: 'Init', msg: 'Application started' });
logger.info({ msg: 'Fetching data...' });
logger.warn({ title: 'Warning', msg: 'Deprecated method used' });
logger.debug({ title: 'Debug', msg: { userId: 123, status: 'active' } });
logger.trace('Trace message');
logger.table({ msg: [{ name: 'Alice' }, { name: 'Bob' }] });

logger.group('My Group');
logger.log({ msg: 'Inside group' });
logger.groupEnd();

logger.time('Load Time');
setTimeout(() => {
  logger.timeEnd('Load Time');
}, 500);

// Custom logger with restricted allowed log types
const config: LoggerConfig = { allowed: new Set(['log', 'error']) };
const customLogger = new TinyLogger(config);
customLogger.log({ msg: 'This will print' });
customLogger.info({ msg: 'This will NOT print' });
// Force override allowed log types to print
customLogger.info({ msg: 'This will print - info', force: true });

API

Method Description
log General logs (console.log)
info Informational logs (console.info)
warn Warnings (console.warn)
error Errors (console.error)
debug Debugging logs (console.debug)
trace Trace stack trace (console.trace)
table Logs table format (console.table)
group Start log group (console.group)
groupEnd End log group (console.groupEnd)
time Start timer (console.time)
timeEnd End timer (console.timeEnd)

Configuration

You can pass an optional LoggerConfig object to TinyLogger constructor to control allowed log types

const logger = new TinyLogger({ allowed: new Set(['log', 'error']) });

License

MIT © Milan Dadhaniya