Manual Reference Source Test
public class | source

Logger

Class for setting up the logger.

Test:

Static Member Summary

Static Public Members
public static

The file transport for the logger.

Constructor Summary

Public Constructor
public

constructor(PopApi: PopApi, options: Object)

Create a new Logger object.

Member Summary

Public Members
public

The log levels the logger middleware will be using.

public

The directory where the log file will be stored.

public

The name of the log file.

Method Summary

Public Methods
public

Formatter method which formats the output to the console.

public

Create a Http logger instance.

public

createLogger(pretty: boolean, quiet: boolean): Object | Winston

Method to create a global logger object based on the properties of the Logger class.

public

Create a logger instance.

public

Formatter method which formats the output to the log file.

public

Create a Console transport.

public

Create a File transport.

public

Get the log message for Http logger.

public

Get the color of the output based on the log level.

public

getLogger(type: string, pretty: boolean, quiet: boolean): Middleware | Winston | undefined

Get a logger object based on the choice.

public

Update the message property and add the splat property to the info object for interpolation.

Private Methods
private

Get the message string from the info object.

Static Public Members

public static fileTransport: Object source

The file transport for the logger.

Public Constructors

public constructor(PopApi: PopApi, options: Object) source

Create a new Logger object.

Params:

NameTypeAttributeDescription
PopApi PopApi
  • nullable: false

The PopApi instance to bind the logger to.

options Object
  • nullable: false

The options for the logger.

options.name string
  • nullable: false

The name of the log file.

options.pretty boolean
  • optional
  • nullable: true

Pretty mode for output with colors.

options.quiet boolean
  • optional
  • nullable: true

No output.

Throw:

TypeError

'name' and 'logDir' are required options for the Logger middleware!

Test:

Public Members

public levels: Object source

The log levels the logger middleware will be using.

public logDir: string source

The directory where the log file will be stored.

public name: string source

The name of the log file.

Public Methods

public consoleFormatter(): Object source

Formatter method which formats the output to the console.

Return:

Object

The formatter for the console transport.

Test:

public createHttpLogger(pretty: boolean): ExpressWinston source

Create a Http logger instance.

Params:

NameTypeAttributeDescription
pretty boolean
  • optional
  • nullable: true

Pretty mode for output with colors.

Return:

ExpressWinston

A configured Http logger instance.

Test:

public createLogger(pretty: boolean, quiet: boolean): Object | Winston source

Method to create a global logger object based on the properties of the Logger class.

Params:

NameTypeAttributeDescription
pretty boolean
  • optional
  • nullable: true

Pretty mode for output with colors.

quiet boolean
  • optional
  • nullable: true

No output.

Return:

Object | Winston

A configured logger.

Test:

public createLoggerInstance(suffix: string, pretty: boolean): Winston source

Create a logger instance.

Params:

NameTypeAttributeDescription
suffix string
  • nullable: false

The suffix for the log file.

pretty boolean
  • optional
  • nullable: true

Pretty mode for output with colors.

Return:

Winston

A configured logger instance.

Test:

public fileFormatter(): Object source

Formatter method which formats the output to the log file.

Return:

Object

The formatter for the file transport.

Test:

public getConsoleTransport(pretty: boolean): Object source

Create a Console transport.

Params:

NameTypeAttributeDescription
pretty boolean
  • optional
  • nullable: true

Pretty mode for output with colors.

Return:

Object

A configured Console transport.

Test:

public getFileTransport(file: string): Object source

Create a File transport.

Params:

NameTypeAttributeDescription
file string
  • nullable: false

The file to log the output to.

Return:

Object

A configured File transport.

Test:

public getHttpLoggerMessage(req: Object, res: Object): string source

Get the log message for Http logger.

Params:

NameTypeAttributeDescription
req Object
  • nullable: false

The request object to log.

res Object
  • nullable: false

The response object to log.

Return:

string

The HtpP log message to print.

Test:

public getLevelColor(level: string): string source

Get the color of the output based on the log level.

Params:

NameTypeAttributeDescription
level string
  • optional
  • default: info
  • nullable: true

The log level.

Return:

string

A color based on the log level.

Test:

public getLogger(type: string, pretty: boolean, quiet: boolean): Middleware | Winston | undefined source

Get a logger object based on the choice.

Params:

NameTypeAttributeDescription
type string
  • optional
  • nullable: true

The choice for the logger object.

pretty boolean
  • optional
  • nullable: true

Pretty mode for output with colors.

quiet boolean
  • optional
  • nullable: true

No output.

Return:

Middleware | Winston | undefined

The logger object.

Test:

public prettyPrintConsole(info: Object): Object source

Update the message property and add the splat property to the info object for interpolation.

Params:

NameTypeAttributeDescription
info Object

The info object processed by logform.

Return:

Object

The info object with the modified message and splat property.

Test:

Private Methods

private _getMessage(info: Object): string source

Get the message string from the info object.

Params:

NameTypeAttributeDescription
info Object

The info object processed by logform.

Return:

string

The message string to print out of the info object.

Test: