Skip to content

Logging component for loopback with add performance instrumentation for remote methods and datasource calls

License

Notifications You must be signed in to change notification settings

yantrashala/loopback-component-logger

Repository files navigation

loopback-component-logger

Logging component for loopback using bunyan logger with additional loopback specific hooks and log management API

NPM

NPM

Build status

Note: Removing support for connector hook instrumentation given changes with loopback-context.

Features

  • Default logger using bunyan
  • Can use of custom bunyan streams to create root logger
  • Hook: Basic performance instrumentation for remote execution
  • Hook: Log management API (configurable)

Usage

Example server.js:

var loopback = require('loopback');
var boot = require('loopback-boot');
var bunyan = require('bunyan');
var rootLogger = bunyan.createLogger({name: 'myloopbackAPI'});
var logger = require('loopback-component-logger')(rootLogger);
var app = module.exports = loopback();

If rootLogger is not provide, the component creates a logger with default bunyan settings:

var loopback = require('loopback');
var boot = require('loopback-boot');
var logger = require('loopback-component-logger')();
var app = module.exports = loopback();

Child loggers can be created for model as shown below. By default child loggers inherit the log level from root.

var logger = require('loopback-component-logger')('TestModel');
module.exports = function(TestModel) {
    logger.debug('Initializing TestModel');
};

To add hooks and log management API to loopback, add configuration to component-config.json:

{
  "loopback-component-explorer": {
    "mountPath": "/explorer"
  },
  "loopback-component-logger": {
      "enableAPI" : true
  }
}

License

MIT.

See Also

About

Logging component for loopback with add performance instrumentation for remote methods and datasource calls

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •