# @nexcella/logger

> Logger for TS/JS application

Latest version **1.0.0** (published 2020-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nexcella/logger
pnpm add @nexcella/logger
yarn add @nexcella/logger
bun add @nexcella/logger
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-03-05 |
| First published | 2020-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andrey Shabanov |
| Maintainers | a-shabanov |
| Keywords | logger |

## Links

- npm: https://www.npmjs.com/package/@nexcella/logger
- Repository: https://github.com/nexcella/js-logger
- Homepage: https://github.com/nexcella/js-logger#readme
- Issues: https://github.com/nexcella/js-logger/issues
- npm.io page: https://npm.io/package/@nexcella/logger

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^3.8.3

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-03-05

## README

# Logger

![](https://img.shields.io/npm/types/typescript.svg)

Simple and minimalistic library for logging. 

## Installation

### npm
```
npm i @nexcella/logger
```

### yarn
```
yarn add @nexcella/logger
```


## Usage

```js
// Create logger instance
const logger = new Logger(config: LoggerConfig)

// Logging messages with different types
logger.debug('Simple debug');
logger.info('Simple info');
logger.warn('Simple warn');
logger.error('Error with context', error);

// Get list of stored logs
logger.getLogs();
/*  ->> output - array of log strings
[
    "[1583397656725] DEBUG: Simple debug",
    "[2146437.1550000506] INFO: Simple info",
    "[2146437.159999972] WARN: Simple warn",
    "[2146437.159999972] ERROR: Error with context, {message: "Error message"}",
]*/
```
## Methods:
### This library supports the following logging methods:
- debug
- info
- warn
- error

All this methods have the following signature
```js
logger.debug(message: string, ...context: any);
```
An unlimited number of contexts can be passed to a method.
```js
logger.debug('message', {text: 'context1'}, {text: 'context2'}, {text: 'context3'});
```
**IMPORTANT** 

All contexts serialized by `JSON.stringify`.

### Getting stored logs
```js
logger.getLogs();
```

Return a list of stored logs in the format:

`[time] LOG_LEVEL message [context]`

[time] calculating by next rules:
 - first message stored current timestamp
 - all next messages stored result of `performance.now()`


## Config:

```typescript
enum LOG_LEVEL {
  DEBUG = 'DEBUG',
  INFO = 'INFO',
  WARN = 'WARN',
  ERROR = 'ERROR',
  NONE = 'NONE'
}
```

| Key | Type | Required | Description |
|--|--|--|--|
| logLevel | LOG_LEVEL | yes | Minimal log level for showing in console. All logs are stored in the storage regardless of this setting |

## Licence

License is MIT

---
_Source: https://npm.io/package/@nexcella/logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
