6.46.8 • Published 4 days ago

@gasket/log v6.46.8

Weekly downloads
35
License
MIT
Repository
github
Last release
4 days ago

@gasket/log

Gasket client and server logger

Installation

npm i @gasket/log @gasket/plugin-log

Configuration

See the @gasket/plugin-log for more details on configuration.

Usage

Levels

Syslog levels are used by this packaged. Each level is exposed as a method on both server and client logger instances.

LevelDescription
debugInformation useful to developers for debugging.
infoNormal operational messages that require no action.
noticeEvents that are unusual, but not error conditions.
warningMay indicate that an error will occur if action is not taken.
errorError conditions
critCritical conditions
alertShould be corrected immediately
emergSystem is unusable

Server

The server requires @gasket/plugin-log to set up a logger instance on the gasket object. This will make the logger instance available for use such as:

gasket.logger.error('Critical malfunction in code execution');
gasket.logger.info('Initializing @gasket/engine `start` lifecycle event');

The server uses winston used for logging. If your app is running locally, all messages are transported to process.stdout aka the console.

Client

For client logging, new logger instances can be instantiated as need. For example, in a component:

import React from 'react';
import Log from '@gasket/log';
import someAction from './some-feature';

class YourComponent extends React.Component {
  constructor() {
    super(...arguments);
    this.logger = new Log();
  }

  doSomething = async () => {
    this.logger.debug('Starting doing something');
    try {
      const results = await someAction();
      this.logger.info(`Did the thing: ${results}`);
    } catch (e) {
      this.logger.error('Something bad happened');
    }
  }

  render() {
    return (
      <div>
        <button onClick={this.doSomething}></button>
      </div>
    )
  }
}

The constructor accepts an object with the following optional properties:

PropertyDescription
levelThe maximum logging level to enable output for. Defaults to info
levelsArray of custom logging level names.
namespaceString for namespacing your logs. See diagnostics for more information. Your namespace is automatically prefixed with gasket:
prodIf set to true enables logging even for production builds. By default production builds have no client-side logging.

NOTE: The client logger uses diagnostics to output log messages to the console. Ensure one of the trigger mechanics for diagnostics in browser is set. The name used for diagnostics is gasket*.

Test

npm test

Alternatively, you can also run the client or server tests separate.

npm run test:client
npm run test:server

License

MIT

6.46.8

4 days ago

6.46.0

3 months ago

6.45.0

4 months ago

6.39.0

11 months ago

6.36.1

1 year ago

6.38.0

1 year ago

6.34.6

2 years ago

6.34.3

2 years ago

6.34.4

2 years ago

6.30.0

2 years ago

6.21.0

2 years ago

6.24.0

2 years ago

6.20.2

2 years ago

6.10.1

2 years ago

6.10.0

2 years ago

6.14.0

2 years ago

6.17.0

2 years ago

6.17.1

2 years ago

6.1.0

3 years ago

6.0.12

3 years ago

6.0.0

3 years ago

6.0.0-canary.13

3 years ago

6.0.0-canary.2

4 years ago

6.0.0-canary.0

4 years ago

5.6.0

4 years ago

5.0.2

4 years ago

5.0.0

4 years ago

5.0.0-canary.4

4 years ago

5.0.0-canary.3

4 years ago

5.0.0-canary.2

4 years ago

5.0.0-canary.1

4 years ago

5.0.0-canary.0

4 years ago