1.1.0 • Published 1 year ago

@cuppachino/logger v1.1.0

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
1 year ago

@cuppachino/logger

Tiny logging utility for tiny projects. Enjoy colored console output without overthinking it.

📦 Installation

@cuppachino/logger

pnpm add @cuppachino/logger
pnpm add -D chalk

or

npm install @cuppachino/logger
npm install --save-dev chalk

🔍 Example Usage

import { createLogger } from '@cuppachino/logger'

const logger = createLogger('main' /* Options */)

logger.tag('example', 'blue', 'bold', 'italic').log('hello world')
logger.log('foo').untag()
logger.log('bar')

🛠️ Configuration

  • colors: an array of colors/modifiers from chalk applied to the logger's prefix (default: 'gray').
  • tagWrapColors: an array of colors/modifiers applied to the characters that wrap each tag (default: 'dim').
  • tagWrapStyle: the characters used to wrap each tag (default: 'square').
type LoggerOptions = {
	colors: Color[]
	tagWrapColors: Color[]
	tagWrapStyle: WrapStyle
	// "angled" | "square" | "curly" | "parens"
}

💪 Methods

  • tag: pushes a tag to the stack
  • untag: removes the previous tag from the stack.
  • log: writes a message to the console, prepended by the logger prefix and any tags.
  • error: throws an error

✏️ Todo

/*
- transports
- levels-like filtering with tags (ideally avoid upfront logger config)
- maybe more... 
*/