# @qiwi/nestjs-enterprise-logger

> Logger module for nestjs enterprise

Latest version **4.1.0** (published 2023-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @qiwi/nestjs-enterprise-logger
pnpm add @qiwi/nestjs-enterprise-logger
yarn add @qiwi/nestjs-enterprise-logger
bun add @qiwi/nestjs-enterprise-logger
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2023-10-09 |
| First published | 2020-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 12 |
| Unpacked size | 237.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 18 |
| Maintainers | antongolub, qiwibot, pismenskiy |
| Keywords | js platform, logger |

## Links

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

## Dependencies (12)

- [rxjs](https://npm.io/package/rxjs.md) ^7.8.1
- [tslib](https://npm.io/package/tslib.md) ^2.6.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [winston](https://npm.io/package/winston.md) ^3.10.0
- [fast-luhn](https://npm.io/package/fast-luhn.md) ^2.0.1
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^10.1.3
- [@qiwi/logwrap](https://npm.io/package/@qiwi/logwrap.md) ^1.5.1
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^10.1.3
- [@types/winston](https://npm.io/package/@types/winston.md) ^2.4.4
- [@qiwi/substrate](https://npm.io/package/@qiwi/substrate.md) ^2.0.4
- [@qiwi/mware-context](https://npm.io/package/@qiwi/mware-context.md) ^1.14.0
- [fast-safe-stringify](https://npm.io/package/fast-safe-stringify.md) ^2.1.1

## 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

- 4.1.0 (latest) — 2023-10-09
- 4.0.2 — 2023-09-26
- 4.0.1 — 2023-09-19
- 4.0.0 — 2023-09-19
- 3.0.0 — 2023-08-11
- 2.0.5 — 2023-06-08
- 2.0.4 — 2023-03-17
- 2.0.3 — 2022-12-08
- 2.0.2 — 2022-09-02
- 2.0.1 — 2022-08-16
- 2.0.0 — 2022-07-26
- 1.6.1 — 2022-07-21
- 1.6.0 — 2022-04-21
- 1.5.6 — 2021-10-01
- 1.5.5 — 2021-09-22
- … 14 more at https://npm.io/package/@qiwi/nestjs-enterprise-logger/versions

## README

# @qiwi/nestjs-enterprise-logger
Nestjs module for logging based on [winston](https://github.com/winstonjs/winston)

## Installation
Following packages should be installed before
- [@qiwi/nestjs-enterprise-config](https://github.com/qiwi/nestjs-enterprise/tree/master/packages/config)
- [@qiwi/nestjs-enterprise-mdc](https://github.com/qiwi/nestjs-enterprise/tree/master/packages/mdc)
```shell script
yarn add @qiwi/nestjs-enterprise-logger
```
## Configuration
Import
```typescript
import { 
  LoggerModule,
  createMetaPipe,
  maskerLoggerPipeFactory,
 } from '@qiwi/nestjs-enterprise-logger'

@Module({
  imports: [
    ConfigModule,
    LoggerModule.register(createMetaPipe(), maskerLoggerPipeFactory()),
    // and so on
  ]
})

export class AppModule {}
```

## Usage
```typescript
  @Injectable()
  class MyService {
    constructor(@Inject('ILogger') private logger: ILogger) {}
    myError() {
      this.logger.error('foo')
    }
    myInfo() {
      this.logger.info('foo')
    }

  }
```

For `createMetaPipe`
```typescript
import {
  logger as log,
} from '@qiwi/nestjs-enterprise-logger'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  const logger = app.get('ILogger')
  app
    .use(log({ logger }))
    .useLogger(logger)

 //...
 logger.info()
```
## Customization
You can inject functions of type `TLoggerPipe` as your own pipes when create `LoggerService` or register `LoggerModule`.
Your pipes will be inserted in the following order:
- `mdc` pipe from `@qiwi/logwrap`;
- `app` pipe (adds app name, app version and os info to log entry);
- your own pipe;
- ...
- your own pipe;
- `logger` pipe (prints log entry).
## API
### Class LoggerModule 
Exports `LoggerService` with token `ILogger`
#### register (...pipes: TLoggerPipe[]): DynamicModule

### Class LoggerService
#### constructor(pipeline: TLoggerPipe[], config: IConfig)
#### push(entry: ILogEntry): void
| field | type  | description |
| --- | --- | --- |
|LogEntry.meta | Record<string, any>| Metadata
|LogEntry.level | ERROR &#124; WARN &#124; INFO &#124; DEBUG &#124; TRACE | Log level
|LogEntry.input | any[] | Data
#### trace(...data: any[]): void
#### debug(...data: any[]): void
#### info(...data: any[]): void
#### warn(...data: any[]): void
#### error(...data: any[]): void

### Function createMetaPipe = () => (entry: ILogEntry): ILogEntry
Creates pipe for metadata injection, used with [@qiwi-private/js-platform-mdc-nestjs](https://github.qiwi.com/common/js-platform/tree/master/packages/mdc-nestjs)

### Function maskerLoggerPipeFactory = () => (entry: ILogEntry): ILogEntry
Creates pipe for pan masking

### Function masker = (input: string | number): string
Masks pans

### [Docs](https://qiwi.github.io/nestjs-enterprise/logger/)

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