npm package: @iti-tic/mystica
Description: Logging service for Nest
Author: ITI
Latest version: 1.0.6

# Mystica

<p align="center">
  <a href="https.//www.iti.es" target="blank"><img src="https://www.iti.es/wp-content/uploads/logo-iti.svg" width="320" alt="ITI Logo" /></a>
</p>
<p align="center">
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>

<!-- ![travis-image](https://api.travis-ci.org/nestjs/nest.svg?branch=master)
[travis-url]: https://travis-ci.org/nestjs/nest
![linux-image](https://img.shields.io/travis/nestjs/nest/master.svg?label=linux)
[linux-url]: https://travis-ci.org/nestjs/nest

  <p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
    <p align="center">
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
  <a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
  <a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p> -->
  <!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->


- [Mystica](#mystica)
  - [Information](#information)
  - [Installation](#installation)
  - [Usage](#usage)
  - [Configuration](#configuration)
  - [Feedback](#feedback)
  - [License](#license)


## Information

Mystica is an open source project that simplifies logging on Nest projects, using other existent loggers such as [winston](https://github.com/winstonjs/winston) with [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file).

## Installation

On the root of your Nest project, run the following command:

```bash
$ npm i --save @iti/mystica
```

## Usage

`Mystica` implements the `LoggerService` interface defined by Nest, so you can replace the default Nest logger with it.

On `main.ts`:
```typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Mystica } from '@iti/mystica'

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: Mystica.forRoot(); // Replace default logger with Mystica
  });
  await app.listen(3000);
}
bootstrap();
```

## Configuration

In order to specify a configuration for Mystica, a `MysticaOptions` object must be passed to the `forRoot` method. If no options are provided, Mystica will use the default configuration.

The `MysticaOptions` interface has two fields:
- `transport`: Indicates the type of transport used
- `options` (optional): Indicates the options for the type of transport. If no options are provided, the default options for the transport specified will be used

Example:
```typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Mystica } from '@iti/mystica'
import { TransportType } from '@iti/mystica/options';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: Mystica.forRoot({
      transport: TransportType.DAILY_ROTATE_FILE,

      options: {
        filename: "logs/%DATE%.log",
        datePattern: "YYYY-MM-DD",
        zippedArchive: false,
        maxSize: "100m",
        maxFiles: "30d"
      }
    })
  });
  await app.listen(3000);
}
bootstrap();
```

## Feedback

Pull requests and issues are welcome!

## License

Mystica is [MIT licensed](LICENSE).