Simple logging utility
Getting Started
Usage
Built With
Contributing
Style logs for the console or terminal.
yarn add @flex-development/log # or npm i @flex-development/log
Customize log entries and create entries based on log Level
presets.
Create a log entry using a Level
preset.
Create a log entry in gray.
import log from '@flex-development/log'
/**
* @file Examples - debug log
* @module log/docs/examples/debug
*/
log('debug log')
Create a log entry with a red cross.
import log, { LogLevel } from '@flex-development/log'
/**
* @file Examples - error log
* @module log/docs/examples/error
*/
log('error log', { level: LogLevel.ERROR })
Create a log entry with a blue info symbol.
import log, { LogLevel } from '@flex-development/log'
/**
* @file Examples - info log
* @module log/docs/examples/info
*/
log('info log', { level: LogLevel.INFO })
Create a log entry with a green tick mark.
import log, { LogLevel } from '@flex-development/log'
/**
* @file Examples - success log
* @module log/docs/examples/success
*/
log('success log', { level: LogLevel.SUCCESS })
Create a log entry with a yellow exclamation point.
import log, { LogLevel } from '@flex-development/log'
/**
* @file Examples - warning log
* @module log/docs/examples/warning
*/
log('warning log', { level: LogLevel.WARN })
interface LogOptions {
/**
* Log arguments.
*
* @default []
*/
args?: any[]
/**
* Bold log arguments **and/or** log data.
*
* @default {args:true}
*/
bold?: LogOptionsBold
/**
* Set log color, and/or override the log figure color set by `level`.
*
* @default {args:'white',data:'white'}
*/
color?: LogOptionsColor
/**
* Override the log figure set by `level`, or omit it altogether.
*/
figure?: keyof typeof figures | NullishString
/**
* Log level.
*
* @default 'DEBUG'
*/
level?: Level
/**
* Use [`echo`][1] instead of `console.log`. Requires [`shelljs`][2].
*
* [1]: https://github.com/shelljs/shelljs#echooptions-string--string-
* [2]: https://github.com/shelljs/shelljs
*/
shell?: boolean
/**
* If `true`, do not log any output.
*/
silent?: boolean
}
enum LogLevel {
DEBUG = 'debug',
ERROR = 'error',
INFO = 'info',
SUCCESS = 'success',
WARN = 'warn'
}
export type Level = keyof typeof LogLevel | LogLevel