https://github.com/cuppachino/logger
Tiny logging utility for tiny projects. Enjoy colored console output without overthinking it.
https://github.com/cuppachino/logger
color logger logging tagging typescript
Last synced: 5 months ago
JSON representation
Tiny logging utility for tiny projects. Enjoy colored console output without overthinking it.
- Host: GitHub
- URL: https://github.com/cuppachino/logger
- Owner: cuppachino
- License: gpl-3.0
- Created: 2022-12-03T04:34:47.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T02:41:34.000Z (over 2 years ago)
- Last Synced: 2024-04-23T20:21:09.898Z (about 2 years ago)
- Topics: color, logger, logging, tagging, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@cuppachino/logger
- Size: 133 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @cuppachino/logger
Tiny logging utility for tiny projects. Enjoy colored console output without
overthinking it.
## 📦 Installation
[@cuppachino/logger](https://www.npmjs.com/package/@cuppachino/logger)
```ps
pnpm add @cuppachino/logger
pnpm add -D chalk
```
or
```ps
npm install @cuppachino/logger
npm install --save-dev chalk
```
## 🔍 Example Usage
```ts
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'`).
```ts
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
```ts
/*
- transports
- levels-like filtering with tags (ideally avoid upfront logger config)
- maybe more...
*/
```