A simple console logger util for use in NodeJS/TypeScript applications.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Go to file
4lch4 6e44ed52c4
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details
1.11.0
10 months ago
.github feat: removed GH Actions. Fucking tired of these things. 2 years ago
src fix: shameful fix for info method... 12 months ago
tests fix: fixed tests 11 months ago
.drone.yml chore: added signature back 10 months ago
.gitignore chore: added `.nyc_output` and `coverage` directories to `.gitignore` 2 years ago
.npmignore chore: added coverage/github dir to .npmignore 2 years ago
.nvmrc chore: changed .nvmrc to v16 instead of v16.6.3 12 months ago
.nycrc.json feat: added support for coverage reports w/ nyc 11 months ago
.prettierignore ci(pretty): project prettied 2 years ago
.prettierrc ci(pretty): project prettied 2 years ago
LICENSE.md chore: moved LICENSE from .github dir to root 2 years ago
README.md ci(pretty): project prettied 2 years ago
package.json 1.11.0 10 months ago
pnpm-lock.yaml feat: added ansi-colors dependency 10 months ago
tsconfig.json refactor: removing ESM 12 months ago

README.md

@4lch4/logger

This module is a small utility module for logging to stdout and, if desired, to also log to files.

Installation

The module is published to the NPM registry so you're able to install it as you would any other module:

# Using NPM
npm install --save @4lch4/logger

# Using Yarn
yarn add @4lch4/logger

# Using PNPM
pnpm install @4lch4/logger

Usage

Using the logger is fairly straight forward. Import the Logger, create a new instance with some optional properties, then use that instance throughout your application:

NOTE: You can also create new instances throughout your app and it will log to the same files/locations.

import { Logger } from '@4lch4/logger'
const logger = new Logger({
  // optional properties
})

logger.info('Hello, world!')
logger.error('Uh oh, something broke...')

Logging Levels

It has 5 "levels" of logging with a color for each, which are as follows (in no particular order):

  • debug - Cyan
  • error - Red
  • info - Gray
  • success - Green
  • warn - Yellow

If you provide a logDir when instantiating the Logger class, each level will have a file. For example, debug would be 2021.03.17-debug.log whereas error would be 2021.03.17-error.log.

Each level has a function to be called for logging at that level. For example, if you want to write to the debug level, you'd do logger.debug('Debug message').