https://github.com/vitalets/logger
Pure typescript logger with levels and prefix support
https://github.com/vitalets/logger
Last synced: 6 months ago
JSON representation
Pure typescript logger with levels and prefix support
- Host: GitHub
- URL: https://github.com/vitalets/logger
- Owner: vitalets
- Created: 2022-01-10T16:00:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-17T17:47:04.000Z (over 3 years ago)
- Last Synced: 2025-03-13T17:52:24.045Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @vitalets/logger
Pure typescript logger with support of prefix, levels, time measure and debug buffering.## Features
* prefix
* log levels
* time measure
* buffering debug messages## Usage
```ts
import { Logger } from '@vitalets/logger';// create logger with prefix and level
const logger = new Logger({ prefix: '[db]:', level: 'info' });// log as usual
logger.debug(42);
logger.log(42);
logger.info(42);
logger.warn(42);
logger.error(42);// measure time
const result = await logger.logTime('fetching...',
() => fetch('http://example.com')
);
// OUTPUT:
// 'fetching...'
// 'fetching... (1.234s)'// buffer debug messages
try {
logger.debug('hello'); // -> outputs nothing as level=info, but stores message in logger.debugBuffer
throw new Error('my error');
} catch (e) {
throw logger.flushDebugBufferToError(e); // attaches debug messages to error stack
}
```## Installation
```
npm i @vitalets/logger
```
> Note: this package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)## API
tbd## License
MIT @ [Vitaliy Potapov](https://github.com/vitalets)