Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LogService

An injectable service that instantiates a Winston logger, and overwrites the existing Nest logging methods with Winston's methods.

Hierarchy

  • Logger
    • LogService

Implements

  • LoggerService
  • Logger

Index

Constructors

constructor

Properties

Private config

The config service

Protected Optional context

context: string

Private logger

logger: WinstonLogger

The winston instance that will be used inside the service

Static Protected Optional instance

instance: Logger | LoggerService

Accessors

httpStream

  • get httpStream(): StreamOptions
  • Exposes a writable stream for http messages that can be used by morgan for generating apache-style logs.

    Returns StreamOptions

Methods

debug

  • debug<T>(message: Loggable<T>, label?: string): void
  • Provides more granual data about the execution flow of the app. Only intended for use in development Like verbose, this method will expand objects/arrays LOG LEVEL: 5

    Type parameters

    • T

    Parameters

    • message: Loggable<T>
    • Optional label: string

    Returns void

error

  • Log errors thrown in the application. For compatibility with Nest, this method can accept a stack trace as the second argument, and a label as its third. Will also accept an Error as the first argument, and will print the stack trace separately. LOG LEVEL: 0

    Parameters

    Returns void

  • Parameters

    Returns void

Protected getInstance

  • getInstance(): Logger | LoggerService
  • Returns Logger | LoggerService

getTimestamp

  • getTimestamp(): string
  • Returns string

http

  • http(message: Writable, label?: string): void
  • Records all requests/responses handled by the application, similar to Apache/nginx logs LOG LEVEL: 3

    Parameters

    • message: Writable
    • Optional label: string

    Returns void

info

  • info(message: Writable, label?: string): void
  • The standard log level, used to for relaying regular information about the status of the app, e.g. Nest startup messages LOG LEVEL: 2

    Parameters

    • message: Writable
    • Optional label: string

    Returns void

Private inspect

log

  • The base logging function used by Nest and TypeORM. They use different formats, so if the first arugment is one of TypeORM's log levels it will expect the log message to be the second argument. Otherwise, the first argument will be treated as the log message, and the second argument as the nest component generating the message. In our implementaiton, log/info messages will go to the info stream, and warnings will go to the warn stream

    Parameters

    Returns void

  • Parameters

    Returns void

logFormat

logMigration

  • Logs messages from the TypeORM migration process. Will write a notification to our verbose stream Will log the full migration message to our debug stream

    Parameters

    Returns void

logQuery

  • Logs every query run by TypeORM, with parameters Will write a notification to the verbose stream Will write the query and parameters to the debug stream

    Parameters

    Returns void

logQueryError

logQuerySlow

  • logQuerySlow(time: number, query: Writable): void
  • Method used by TypeORM to flag long-running queries that could indicate performance issues. The threshold for slow queries is set by the maxQueryExecutionTime in the connection options in app.module.ts Messages will be passed to our warn function

    Parameters

    Returns void

logSchemaBuild

  • logSchemaBuild(message: Writable): void
  • Logs messages from the TypeORM schema building process. Will write a notification to our verbose stream Will log the full schema build message to our debug stream

    Parameters

    Returns void

setContext

  • setContext(context: string): void
  • Parameters

    • context: string

    Returns void

verbose

  • verbose<T>(message: Loggable<T>, label?: string): void
  • Records more detailed information about the running application. Includes:

    • ID of user's associated with requests
    • Notifications about data read from and written to the database

    This method will expand objects/arrays passed as arguments, such as:

    • Body content of POST/PUT requests
    • Body content returned in responses LOG LEVEL: 4

    Type parameters

    • T

    Parameters

    • message: Loggable<T>
    • Optional label: string

    Returns void

warn

  • warn(message: Writable, label?: string): void
  • Record issues that don't degrade the application, but may produce less-desirable results. LOG LEVEL: 1

    Parameters

    • message: Writable
    • Optional label: string

    Returns void

Static debug

  • debug(message: any, context?: string, isTimeDiffEnabled?: boolean): void
  • Parameters

    • message: any
    • Optional context: string
    • Optional isTimeDiffEnabled: boolean

    Returns void

Static error

  • error(message: any, trace?: string, context?: string, isTimeDiffEnabled?: boolean): void
  • Parameters

    • message: any
    • Optional trace: string
    • Optional context: string
    • Optional isTimeDiffEnabled: boolean

    Returns void

Static getTimestamp

  • getTimestamp(): string
  • Returns string

Static log

  • log(message: any, context?: string, isTimeDiffEnabled?: boolean): void
  • Parameters

    • message: any
    • Optional context: string
    • Optional isTimeDiffEnabled: boolean

    Returns void

Static overrideLogger

  • overrideLogger(logger: LoggerService | LogLevel[] | boolean): void
  • Parameters

    • logger: LoggerService | LogLevel[] | boolean

    Returns void

Static verbose

  • verbose(message: any, context?: string, isTimeDiffEnabled?: boolean): void
  • Parameters

    • message: any
    • Optional context: string
    • Optional isTimeDiffEnabled: boolean

    Returns void

Static warn

  • warn(message: any, context?: string, isTimeDiffEnabled?: boolean): void
  • Parameters

    • message: any
    • Optional context: string
    • Optional isTimeDiffEnabled: boolean

    Returns void

Generated using TypeDoc