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

thunder-log

v1.0.2

Published

The logger used for Shared Services Logging.

Downloads

10

Readme

thunder-log

Authors: Greg Morgan + Ryan Cooper
Built for Vertafore Shared Services logging in javascript.

About thunder-log

Implementing winston, a logger for javascript applications, thunder-log is a wrapper around this which handles the necessary fields, formatting, and transports for our team.

How to use thunder-log

Creating a logger in your project

Install thunder-log into the project

npm install --save thunder-log

Once installed in the project, add thunder-log into a file and call the logger

const thunder-log = require('thunder-log');
const logger = thunder-log.getLogger();
getLogger()

The call for a logger can take no arguments, determining the appropriate logger based on the node environment, or it can be passed the name of the logger needed.

thunder-log.getLogger('development');
// returns a logger which will print to console and file (log.txt) set to a level of debug

thunder-log.getLogger('production');
// return a logger which print json formatted logs to console set to a level of info

thunder-log.getLogger('test');
// return a test logger which overrides the functions of the logger to use in testing with a level of debug
Logging levels

thunder-log implements several standard logging levels such as:

  • debug
  • info
  • warn
  • error

The level of the logger determine which logs are passed to the transport to be recorded.
Loggers of these levels will only print messages of level equal to them or lower on the list.
ie: a logger of level 'info' does not print debug statements but will print warn and error statement

A basic logging statement
logger.write('info', 'This is my first info');  

Alternatively;

logger.info('This is also my first info');  

thunder-log supports both methods of writing a logging statement. This is true as well for debug, warn, and error statements with the exception of error statements only accepting an object and not a string.

logger.write('debug', 'I am debugging');
logger.debug('I am also debugging');  

logger.write('warn', 'I am warning');
logger.warn('I am also warning'); 
Error logging

Errors require an object of two fields (Summary and ExceptionDetails) in order to make a valid logging statement

logger.write('error', { Summary: 'This is my error', ExceptionDetails: 'This is my error message' });
logger.error({ Summary: 'This is my error', ExceptionDetails: 'This is my error message' });  
Accepted Fields

All logging levels can take in additional fields depending on the needs of the statement.

- CorrelationId	(string) Attached to all requests sent or generated for all responses, used for tracking http request/responses throughout their lifetime
- SequenceNumber (int) The iteration of a corresponds to a CorrelationId
- ApplicationId* (string) Applied to logs of a given application ex: 'VMG' for Vertafore Mobile Gateway logs
- Severity* (string) The severity of the log
- Timestamp* (dateTime) UTC, The time which the log was made
- LoggerId (string) The component responsible for where the logging took place; a method name, a class, or a file
- UserId (string) Identifier for a particular user (see PII requirements to not post any information that can be tracked back to the user)
- Summary (string) Detailed description of the log
- Action (string) Http request verbs; GET, POST, DELETE, etc
- ActionTarget (string) What module, service, or class is the target of the operation
- ActionResult (string) What was the result of the action; success, fail, timeout
- ExceptionDetails (string) Contains the exception code corresponding to the message passed using the Shared Services Exceptions Handling Schema ex: '400: Invalid Input Error'
- StackInfo (string) When errors occur, can provide a stack trace in the log
- AdditionalDetails (string) Information which should be provided but does not fit a category above

* Fields which are handled by the logger and do not need to be passed into the logging statement  

Examples

These examples function as templates for logging statements.

Info statement with all generally used fields
logger.write('info',
    {
        CorrelationId: '',
        SequenceNumber: '',
        LoggerId: '',
        UserId: '',
        Summary: '',
        Action: '',
        ActionTarget: '',
        ActionResult: '',
        AdditionalDetails: ''
    }
);
Error statement with inclusion of required error fields
logger.write('error',
    {
        CorrelationId: '',
        SequenceNumber: '',
        LoggerId: '',
        UserId: '',
        Summary: '',
        Action: '',
        ActionTarget: '',
        ActionResult: '',
        ExceptionDetails: '',
        StackInfo: '',
        AdditionalDetails: ''
    }
);