Git Product home page Git Product logo

logdna-winston's Introduction

Node.js Winston library for logging to LogDNA


All Contributors

Install

$ npm install --save logdna-winston

API

Please see @logdna/logger for instantiation options to passthrough to LogDNA's logger client.

Winston Transport

This module also provides a transport object, which can be added to winston using:

const logdnaWinston = require('logdna-winston');
const winston = require('winston');
const logger = winston.createLogger({});
const options = {
    key: apikey,
    hostname: myHostname,
    ip: ipAddress,
    mac: macAddress,
    app: appName,
    env: envName,
    level: level, // Default to debug, maximum level of log, doc: https://github.com/winstonjs/winston#logging-levels
    indexMeta: true // Defaults to false, when true ensures meta object will be searchable
}

// Only add this line in order to track exceptions
options.handleExceptions = true;

logger.add(new logdnaWinston(options))

// Log Examples

// log with meta and human readable message for Live Tail (structure upon log line expansion in-app)
let log_obj_info = {
    message: 'USER 101010 SUCCESSFUL LOGIN',
    user_id: '101010',
    trace_id: '163e169e-a326-4b1b-a8f5-7169dd4eeca8',
}
logger.log({      
    level: 'info',                         // Required.     
    message: JSON.stringify(log_obj_info), // Optional. If not provided, the stringified (read JSON) object (minus level) will be sent as the payload
                                           //           If specified, message will be the body/payload while the other parameters are then
    indexMeta: true,                       //               Optional. If not provided, it will use the default.
    geoloc: {lat:37.386,lon:-122.084}      //               Optional. Properties besides level, message and indexMeta are up to you
                                           //                         and stored in the "meta" field
})

// log errors with structure and the proper level
try {
    throw new Error("It's a trap!");
} catch(e) {
    logger.log({
        level: 'error',
        message: { // Quickly break out the important error information into searchable fields within LogDNA via JSON 
            message:e.message,
            error:{code:e.code,stack:e.stack},        
            trace_id: 'a077f0ad-ed0f-423b-b8d8-e0f9e3165d9f'
        } // no meta included this time
    })
}

// log with convenience functions
logger.info('Info: Log from LogDNA-winston')

// a payload without 'message' will log the stringified (read JSON) object as the message.  Same functionality as logger.log minus the level bit
logger.warn({
    key: 'value',
    text: 'This is some text to get logged',
    bool: true
})

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Muaz Siddiqui

๐Ÿ’ป ๐Ÿ“–

Samir Musali

๐Ÿ’ป ๐Ÿ“–

Darin Spivey

๐Ÿ’ป ๐Ÿ“–

Mike Huang

๐Ÿ’ป ๐Ÿ“–

Brian Conn

๐Ÿ“–

Mario Casciaro

๐Ÿ’ป

vilyapilya

๐Ÿ”ง

Mike Del Tito

๐Ÿ’ป ๐Ÿ”ง

This project follows the all-contributors specification. Contributions of any kind welcome!

License

Copyright ยฉ LogDNA, released under an MIT license. See the LICENSE file and https://opensource.org/licenses/MIT

Happy Logging!

logdna-winston's People

Contributors

mdeltito avatar smusali avatar logdnabot avatar darinspivey avatar respectus avatar lyhuang avatar braxtonj avatar theconnman avatar mariocasciaro avatar vilyapilya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.