Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

@brainhubeu/hadron-logger

Package Overview
Dependencies
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brainhubeu/hadron-logger

Hadron logger

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
5
-61.54%
Maintainers
6
Weekly downloads
 
Created
Source

Logger for Hadron

Overview

Hadron Logger provides an option to replace the default hadron logger (bunyan) to the one of your choice.

Installation

npm install @brainhubeu/hadron-logger --save

More info about installation

Initialization

Pass the package as an argument for the Hadron bootstrapping function:

// ... importing and initializing other components

hadron(expressApp, [require('@brainhubeu/hadron-logger')], config);

That way, you should be able to get it from the Container like that:

const logger = container.take('logger');
logger.log('Hello, I am your logger');
logger.warm('Look out! I am your logger!');
logger.debug('Am I your logger?');
logger.error('I am not your logger!');

Notice: logger is a container key only for the default logger.

Configuration

To setup your own logger, you need to provide an adapter first. You can do that by importing the registerAdapter method and calling it with name and provider function for your logger, like that:

const registerAdapter = require('@brainhubeu/hadron-logger').registerAdapter;
registerAdapter('myOwnLogger', function(config) {
  return {
    log: function(message) {
      console.log(message);
    },
    warn: function(message) {
      console.warn(message);
    },
    debug: function(message) {
      console.debug(message);
    },
    error: function(message) {
      console.error(message);
    },
  };
});

Provider takes the Hadron logger config as the first parameter.

After your adapter is set up, you can define your logger in the Hadron configuration and retrieve it using the logger's name.

const hadronConfig = {
  // ...other stuff
  logger: {
    name: 'myLoggerName',
    type: 'myOwnLogger',
  },
};

// hadron initialization

const logger = Container.take('myLoggerName');

Multiple loggers

You can define multiple loggers for your application. To do that you just need to provide adapters for each of them and define them in the configuration.

const hadronConfig = {
  // ...other stuff
  logger: [
    { name: 'Logger1', type: 'logger1' },
    { name: 'logger2', type: 'logger2' },
    { name: 'logger3', type: 'logger3' },
  ],
};

// hadron initialization

container.take('Logger1');
container.take('Logger2');
container.take('Logger3');

Keywords

hadron

FAQs

Package last updated on 29 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts