1.0.3 • Published 6 months ago

@milandadhaniya/tiny-logger-js v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@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

MethodDescription
logGeneral logs (console.log)
infoInformational logs (console.info)
warnWarnings (console.warn)
errorErrors (console.error)
debugDebugging logs (console.debug)
traceTrace stack trace (console.trace)
tableLogs table format (console.table)
groupStart log group (console.group)
groupEndEnd log group (console.groupEnd)
timeStart timer (console.time)
timeEndEnd 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

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago