# nestjs-mongolog

> Package for logging things into mongodb.

Latest version **2.1.4** (published 2022-06-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install nestjs-mongolog
pnpm add nestjs-mongolog
yarn add nestjs-mongolog
bun add nestjs-mongolog
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2022-06-28 |
| First published | 2022-06-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 34.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Anderson Gonçalves |
| Maintainers | andersonssg |
| Keywords | mongodb, log, nestjs, nestjs-mongolog |

## Links

- npm: https://www.npmjs.com/package/nestjs-mongolog
- Repository: https://github.com/Anderson-SG/nestjs-mongolog
- Homepage: https://github.com/Anderson-SG/nestjs-mongolog#readme
- Issues: https://github.com/Anderson-SG/nestjs-mongolog/issues
- npm.io page: https://npm.io/package/nestjs-mongolog

## Dependencies (6)

- [rxjs](https://npm.io/package/rxjs.md) ^7.5.5
- [tslog](https://npm.io/package/tslog.md) ^3.3.3
- [dotenv](https://npm.io/package/dotenv.md) ^16.0.1
- [mongodb](https://npm.io/package/mongodb.md) ^4.7.0
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.0.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.1.4 (latest) — 2022-06-28
- 2.1.2 — 2022-06-28
- 2.1.1 — 2022-06-28
- 2.0.0 — 2022-06-28
- 1.0.3 — 2022-06-26
- 1.0.2 — 2022-06-26
- 1.0.1 — 2022-06-26
- 1.0.0 — 2022-06-26

## README

# nestjs-mongolog

[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Anderson-SG_nestjs-mongolog&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Anderson-SG_nestjs-mongolog)

## Description

This package was created with the intention of facilitating and standardizing the writing of nestjs application logs in mongodb databases.

## Instalation

`npm i --save nestjs-mongolog`

## Quick Start

Import **MongodbLogModule** and use **forRoot** or **forRootAsync** static methods on your **Module** for initial configuration:</li>

```typescript
MongodbLogModule.forRootAsync({
  imports: [ConfigModule],

  useFactory: async (configService: ConfigService) => ({
    connectionString: configService.get<string>('DATABASE_URI'),
    databaseName: configService.get<string>('DATABASE_NAME'),
    collectionName: configService.get<string>('LOGS_COLLECTION_NAME'),
  }),

  inject: [ConfigService],
});
```

The fields to be passed in the configuration are as follows:

| Field Name             | Field Function                                                              |
| ---------------------- | --------------------------------------------------------------------------- |
| **connectionString**   | The connection uri for your mongodb database.                               |
| **databaseName**       | The name of the database to which the logs will be written.                 |
| **mongoClientOptions** | Additional settings for mongoClient like: `{ useUnifiedTopology: true }`    |
| **collectionName**     | The name of the collection where this module's logs will be written.        |
| **showInConsole**      | Enables or disables the display of log messages in the application console. |

Import **MongodbLogService** on your service or controller and use the logging methods provided.

```typescript
import { Controller, Get } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  constructor(private readonly logger: MongodbLogService) {}

  @Get()
  findAll(): string {
    this.logger.info('listing all cats.', this.findAll.name);
    return 'This action returns all cats';
  }
}
```

Usage:

```typescript
await this.logger.info('MESSAGE');
await this.logger.info({ fo: bar, ov: av });
await this.logger.info({ fo: bar, ov: av }, 'currentFunctionName ou any ContextData');
await this.logger.error('MESSAGE');
await this.logger.warn('MESSAGE');
await this.logger.debug('MESSAGE');
await this.logger.silly('MESSAGE');
await this.logger.fatal('MESSAGE');
```

You don't need to await writing logs if you don't want to.

</ol>

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