npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@netsells/netsells-logger-adonis

v1.4.1

Published

This module wraps the `@netsells/netsells-logger-node` package in an Adonis Service Provider for easy integration into Adonis projects. This module will also provide a `/__logger` route in your application, which can receive a `POST` with a JSON payload o

Downloads

13

Readme

Netsells Logger Adonis Provider

This module wraps the @netsells/netsells-logger-node package in an Adonis Service Provider for easy integration into Adonis projects. This module will also provide a /__logger route in your application, which can receive a POST with a JSON payload of severity and body. For further info, check out the Nuxt Integration.

Installation

yarn add @netsells/netsells-logger-adonis

Add the following line to your Adonis providers in start/app.js:

const providers = [
    '@netsells/netsells-logger-adonis/providers/NetsellsLoggerProvider',
];

To set the logger as your applications default, update the default logger transport in your Adonis application config:

module.exports = { 
    logger: {
        transport: 'netsells',
    },
};

Also add a new config entry for the Netsells transport below:

module.exports = { 
    logger: {
        netsells: {
            driver: 'netsells',
            name: 'application-name',
            // This is retrieved from the APP_ENV variable if set, 
            // but you can override here with one of the following 
            // options as a baseline: 'local', 'staging', 'production'
            environment: 'production', 
            // Netsells logger config values
        },
    },
};

Usage

This module will simply enable a new logger transport in your application, so can be utilised in the same way as normal.

const Logger = use('Logger');

Logger.info('Some information');
Logger.warning('Some information');
Logger.error('Some information');
Logger.debug('Some information');

Check out the Logger Documentation for more details.

The second parameter can be set to pass additional data through to the logger instance. This format matches the format outlined in the Logging Docs.

// You can pass exceptions directly and they will be parsed for you
try {
    throw new Error('Some application logic error');
} catch (e) {
    Logger.error('An error was thrown in application logic', {
        exception: e,
    });
}

// You can also add additional context data
Logger.error('An error was thrown in application logic', {
    exception: e,
    context: {
        formData: request.all(),    
    },
});

Config

The following values can be set:

name

  • Type: string
  • Default: 'adonis-app'

The application name that logs should be grouped by. This should be changed.

level

  • Type: string
  • Default: 'info'

The default logging level.

directory

  • Type: string
  • Default: {appRoot}/logs

The directory that log files should be stored in. This should be an absolute path.

component

  • Type: string
  • Default: 'frontend'

The component to group logs by.

subComponent

  • Type: string
  • Default: 'node'

The sub-component to group logs by.

Integrations

This package also provides some integrations for frontend frameworks.

Nuxt

To enable a few helper methods in your application to communicate with your server-side logger, you can register the module in your nuxt config:

module.exports = {
    modules: [
        '@netsells/netsells-logger-adonis/nuxt',    
    ],
};

The following methods are then available to be used through your application:

// Generic log
this.$log('message', 'severity');
// Severity must be one of: 
// emerg, alert, crit, error, warning, notice, info, debug 

// You can add an optional logger object as the second parameter if needed 
this.$log('message', {
    // Logger data
}, 'severity');

// Error shorthand
this.$log('message', {
    // optional log object
});

// Info shorthand
this.$logInfo('message', {
    // optional log object
});

Ensure you allow the /__logger endpoint to be accessed via POST without csrf protection by updating your csrf.filterUris value in your shield.js config in Adonis, e.g.:

module.exports = {
    csrf: {
        enable: true,
        filterUris: [
            '/__logger',
        ],
    },
};

Example usage

async login() {
    try {
        await this.$auth.login();
    } catch (e) {
        this.$logError('An error occurred when logging in', {
            exception: e,
            // This options object follows the same format 
            // as the server-side component
        });
    }    
},