Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

flex-development/log

Folders and files

NameName
Last commit message
Last commit date
Oct 30, 2021
Oct 10, 2021
Oct 14, 2021
Sep 16, 2021
Oct 30, 2021
Oct 30, 2021
Oct 1, 2021
Oct 30, 2021
Oct 30, 2021
Oct 30, 2021
Oct 10, 2021
Oct 11, 2021
Oct 3, 2021
Oct 3, 2021
Oct 30, 2021
Oct 30, 2021
Oct 10, 2021
Oct 1, 2021
Oct 30, 2021
Oct 10, 2021
Oct 10, 2021
Oct 14, 2021
Oct 1, 2021
Nov 1, 2021
Oct 3, 2021
Aug 21, 2021
Sep 15, 2021
Oct 30, 2021
Oct 3, 2021
Nov 1, 2021
Oct 30, 2021
Oct 30, 2021
Oct 3, 2021
Oct 30, 2021
Oct 3, 2021
Oct 30, 2021
Oct 14, 2021
Nov 1, 2021

Repository files navigation

⌨️ log

Simple logging utility

Conventional Commits TypeScript tested with jest

Overview

Getting Started
Usage
Built With
Contributing

Getting Started

Style logs for the console or terminal.

Installation

yarn add @flex-development/log # or npm i @flex-development/log

Usage

Customize log entries and create entries based on log Level presets.

Levels

Create a log entry using a Level preset.

log-levels

Debug

Create a log entry in gray.

import log from '@flex-development/log'

/**
 * @file Examples - debug log
 * @module log/docs/examples/debug
 */

log('debug log')

Error

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 })

Info

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 })

Success

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 })

Warning

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 })

Options

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

Built With

  • chalk - Terminal string styling
  • shelljs - Unix shell commands implementation for Node.js