Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/v3xlabs/logger

Zero dependency, light-weight, blazing fast customizable logging library
https://github.com/v3xlabs/logger

console javascript logger logging logging-library nodejs typescript

Last synced: 12 days ago
JSON representation

Zero dependency, light-weight, blazing fast customizable logging library

Awesome Lists containing this project

README

        

![lvksh logger](./assets/banner.png)

[![MINIFIED SIZE](https://img.shields.io/bundlephobia/min/@lvksh/logger.svg)]()
[![COVERAGE](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)]()
[![LANGUAGES](https://img.shields.io/github/languages/top/lvkdotsh/logger)]()
[![DEPENDENCIRES](https://img.shields.io/badge/dependencies-0-brightgreen.svg)]()
[![NPM](https://img.shields.io/npm/dt/@lvksh/logger)]()

Zero dependency, lightweight, blazingly fast customizable logging library

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [examples](#usage) (To get you going)
- [LoggerConfig](#loggerconfig) (Customization for the entire logger)
- [MethodConfig](#methodconfig) (Customization on a per-method basis)
- [Shimming console.log](#shimming-console.log)

## Installation

Using `npm`:

```sh
npm install @lvksh/logger
```

or if you prefer to use the `yarn` package manager:

```sh
yarn add @lvksh/logger
```

## Usage

Get started by creating your logger

```ts
import { createLogger } from '@lvksh/logger';
import chalk from 'chalk';

const log = createLogger(
{
ok: {
label: chalk.greenBright`[OK]`,
newLine: '| ',
newLineEnd: '\\-',
},
debug: chalk.magentaBright`[DEBUG]`,
info: {
label: chalk.cyan`[INFO]`,
newLine: chalk.cyan`⮡`,
newLineEnd: chalk.cyan`⮡`,
},
veryBigNetworkError: chalk.bgRed.white.bold`[NETWORK]`,
},
{ padding: 'PREPEND' },
console.log
);
```

And now log to your hearts content

```ts
log.ok('This is the best logging', 'library', 'you');
log.info('will probably');
log.debug('ever use');
log.veryBigNetworkError`Never Gonna Give You Up!`;
log.debug('in', 'your', 'life', "you're", 'welcome');
log.info('item 1', 'item 2', 'item 3', 'item 4', 'item 5');
```

Which produces the following result

Other Themes:

### LoggerConfig

This section is still work in progress.

### MethodConfig

This section is still work in progress.

### Shimming `console.log`

Do you still type `console.log` out of habit? Not a problem, simply run `shimLog` with your logger, and your log function of choice and voila.
Now every stray `console.log` will be on steroids from now on!

```typescript
import { createLogger, shimLog } from '@lvksh/logger';
import chalk from 'chalk';

const log = createLogger({
debug: chalk.magentaBright`[DEBUG]`,
});

// Replaces `console.log` with `log.debug` !
shimLog(log, 'debug');
```

### File Logging

```typescript
import { join } from 'path';
import { createLogger } from '@lvksh/logger';
import { FileLogger } from '@lvksh/logger/lib/file-log';

const log = createLogger(
{
OK: 'OK',
INFO: 'INFO',
},
{ divider: ' | ' },
FileLogger({
mode: 'NEW_FILE',
path: join(__dirname, 'logs'),
namePattern: 'test.txt',
})
);

log.OK('Hello World');
```

### Multi Logging

```typescript
import { join } from 'path';
import { createLogger } from '@lvksh/logger';
import { FileLogger, FileLoggerConfig } from '@lvksh/logger/lib/file-log';

const fileConfig: FileLoggerConfig = {
mode: 'NEW_FILE',
path: join(__dirname, '../logs'),
namePattern: 'test.txt'
}
const methodConfig = {
OK: 'OK',
INFO: 'INFO'
}

const log = createLogger(
methodConfig,
{ divider: ' | ' },
[FileLogger(fileConfig), console.log]
);

export default log;

log.OK('Hello World');
```

## Contributors

[![](https://contrib.rocks/image?repo=lvkdotsh/logger)](https://github.com/lvkdotsh/logger/graphs/contributors)

## LICENSE

This package is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0).

Regex matching within this package is sourced from [ansi-regex](https://github.com/chalk/ansi-regex), which is licensed under the [MIT](https://github.com/chalk/ansi-regex/blob/main/license) license.