2.1.0 • Published 1 year ago

@shopify/logger v2.1.0

Weekly downloads
169
License
MIT
Repository
github
Last release
1 year ago

@shopify/logger

Build Status Build Status License: MIT npm version

Opinionated logger for production-scale applications.

Installation

yarn add @shopify/logger

Usage

Instantiation

A basic logger can be created simply by calling the Logger constructor:

const logger = new Logger();

The Logger constructor also takes an options object. For example:

const logger = new Logger({
  name: 'my-logger',
  formatter: new ConsoleFormatter(),
});

The options object adheres to the following interface:

interface LoggerOptions {
  formatter?: Formatter;
  name?: string;
}

The name of a logger will be used as it's root scope. A formatter may use this to provide context when outputting a log entry. For example, the ConsoleFormatter will preface each log with its scope, such as:

[my-logger] ℹ info - some log text

A Formatter is simply an object that implements the Formatter interface:

export interface Formatter {
  format(entry: FormatEntry): any;
}

In addition to writing your own formatter, See Formatters below for a list of provided formatters.

Logging

Given the logger above, we can log information to the console using the built-in info, warn, and error functions. For example:

logger.info('Hello, world!');
logger.warn('Something bad might happen');
logger.error(new Error('Operation not permitted.'));

Formatters

This package provides the following formatters:

  • ConsoleFormatter

ConsoleFormatter

Formats and prints logs via console.log, console.warn, and console.error.

Screenshots

`ConsoleFormatter` sample error output

`ConsoleFormatter` sample log output on a dark background

`ConsoleFormatter` sample log output on a light background

2.1.0

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.11

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.10

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago