fran-logging
Fran logger is a simple logging with an easy configuration. Supports level based filtering and tagging that keeps your logs readable and uncluttered!
Simple Features
- Small footprint, around 500 bytes
- Filter by level,
ERROR > WARN > INFO > TRACE > DEBUG
- Filter by tag,
'security' | 'anything'
Install
npm install fran-logging
Initialize
Tags typically refer to a subsystem or component like 'security'
or FooBar.name
. When fran-logging is initialized, tags can be assigned a level. A message is logged when its level is greater than or equal to its tag
's assigned level.
import { log, LogLevel } from 'fran-logging';
import chalk from 'chalk';
const logger = {
[LogLevel.ERROR]: (tag, msg, params) => console.error(`[${chalk.red(tag)}]`, msg, ...params),
[LogLevel.WARN]: (tag, msg, params) => console.warn(`[${chalk.yellow(tag)}]`, msg, ...params),
[LogLevel.INFO]: (tag, msg, params) => console.log(`[${chalk.brightGreen(tag)}]`, msg, ...params),
[LogLevel.TRACE]: (tag, msg, params) => console.log(`[${chalk.cyan(tag)}]`, msg, ...params),
[LogLevel.DEBUG]: (tag, msg, params) => console.log(`[${chalk.magenta(tag)}]`, msg, ...params),
} as Record<LogLevel, (tag: string, msg: unknown, params: unknown[]) => void>;
log.init({ transporter: 'INFO', security: 'ERROR', system: 'OFF' }, (level, tag, msg, params) => {
logger[level as keyof typeof logger](tag, msg, params);
});
Usage
import { log, tag } from 'fran-logging';
log.error(tag.security, 'not authorized', statusCode);
log.warn('transporter', 'Evil twin detected!');
log.info(tag.security, 'login successful');
log.trace(tag.system, 'entering engine room');
log.debug(tag.system, { warpFactor, starDate });
log.error(tag.system, 'eject the warp core', error);
log.init({ loader: 'ERROR', system: 'INFO' });
log.init();
Advanced Usage
Create an instance with its own tags and callback.
import { Log, tag } from 'fran-logging';
const myLog = new Log().init(
{ loader: 'INFO', security: 'ERROR' },
(level, tag, msg, params) => {
console.log(`${level}: [${tag}] `, msg, ...params);
});
myLog.info(tag.security, 'login successful');