### File

`src/core/services/common/logger.service.ts`

### Description

service for logging

### Index

###### Properties

- Private Readonly Optional context
- Private Readonly logger

###### Methods

- Static createlogger
- Public debug
- Public error
- Private format
- Public log
- Public verbose
- Public warn

### Constructor

`constructor(context: string)`
Defined in src/core/services/common/logger.service.ts:16

constructor for the logger

Parameters :

Name | Type | Optional
context | `string` | No

### Methods

Static createlogger
`createlogger(context: string)`
Defined in src/core/services/common/logger.service.ts:32

creates the logger

Parameters :

Name | Type | Optional | Description
context | `string` | No | context

Returns : `LoggerService`

logger

Public debug
`debug(message: string, ...args: any[])`
Defined in src/core/services/common/logger.service.ts:69

logs the debug message

Parameters :

Name | Type | Optional | Description
message | `string` | No | message
args | `any[]` | No | arguments

Returns : `void`

Public error
`error(message: string, error?: string | Error, ...args: any[])`
Defined in src/core/services/common/logger.service.ts:51

logs the error message

Parameters :

Name | Type | Optional | Description
message | `string` | No | message
error | `string | Error` | Yes | error
args | `any[]` | No | arguments

Returns : `void`

Private format
`format(message: string, args?: string[])`
Defined in src/core/services/common/logger.service.ts:88

formats the message

Parameters :

Name | Type | Optional | Description
message | `string` | No | message
args | `string[]` | Yes | arguments

Returns : `any`

formatted message

Public log
`log(message: string, ...args: any[])`
Defined in src/core/services/common/logger.service.ts:41

logs the message

Parameters :

Name | Type | Optional | Description
message | `string` | No | message
args | `any[]` | No | arguments

Returns : `void`

Public verbose
`verbose(message: string, ...args: any[])`
Defined in src/core/services/common/logger.service.ts:78

logs the verbose message

Parameters :

Name | Type | Optional | Description
message | `string` | No | message
args | `any[]` | No | arguments

Returns : `void`

Public warn
`warn(message: string, ...args: any[])`
Defined in src/core/services/common/logger.service.ts:60

logs the warning message

Parameters :

Name | Type | Optional | Description
message | `string` | No | message
args | `any[]` | No | arguments

Returns : `void`

### Properties

Private Readonly Optional context
Type : `string`
Defined in src/core/services/common/logger.service.ts:16
context

Private Readonly logger
Type : `Logger`
Defined in src/core/services/common/logger.service.ts:12
logger

    import { Injectable, Logger, LoggerService as NestLoggerService } from '@nestjs/common';
    import { formatWithOptions } from 'util';

    /**
     * service for logging
     */
    @Injectable()
    export class LoggerService implements NestLoggerService {
      /**
       * logger
       */
      private readonly logger: Logger;
      /**
       * context
       */
      private readonly context?: string;
      //=============================================================================================================
      /**
       * constructor for the logger
       * @param context
       */
      constructor(context: string) {
        this.logger = new Logger(context);
        this.context = context;
      }
      //=============================================================================================================
      /**
       * creates the logger
       * @param context context
       * @returns logger
       */
      static createlogger(context: string): LoggerService {
        return new LoggerService(context);
      }
      //=============================================================================================================
      /**
       * logs the message
       * @param message message
       * @param args arguments
       */
      public log(message: string, ...args: any[]) {
        this.logger.log(this.format(message, args));
      }
      //=============================================================================================================
      /**
       * logs the error message
       * @param message message
       * @param error error
       * @param args arguments
       */
      public error(message: string, error?: string | Error, ...args: any[]) {
        this.logger.error(this.format(message, args), error instanceof Error ? error.stack : error);
      }
      //=============================================================================================================
      /**
       * logs the warning message
       * @param message message
       * @param args arguments
       */
      public warn(message: string, ...args: any[]) {
        this.logger.warn(this.format(message, args));
      }
      //=============================================================================================================
      /**
       * logs the debug message
       * @param message message
       * @param args arguments
       */
      public debug(message: string, ...args: any[]) {
        this.logger.debug(this.format(message, args));
      }
      //=============================================================================================================
      /**
       * logs the verbose message
       * @param message message
       * @param args arguments
       */
      public verbose(message: string, ...args: any[]) {
        this.logger.verbose(this.format(message, args));
      }
      //=============================================================================================================
      /**
       * formats the message
       * @param message message
       * @param args arguments
       * @returns formatted message
       */
      private format(message: string, args?: string[]) {
        if (!args || !args.length) return message;

        return formatWithOptions({ colors: true, depth: 5 }, message, ...args);
      }
      //=============================================================================================================
    }

# results matching ""

# No results matching ""