Giter VIP home page Giter VIP logo

winston-log2gelf's Introduction

winston-log2gelf

A Graylog2 or GELF transport for [email protected]. Supports HTTP(S) & TCP/TCP over TLS protocols.

If you're looking for the 1.x version supporting Winston < 3.x, check [email protected].

Installation

  $ npm install --save winston-log2gelf

Usage

  const winston = require('winston');
  const Log2gelf = require('winston-log2gelf');

  const logger = winston.createLogger({
    transports: [
        new winston.transports.Console({
            level: 'info',
            handleExceptions: true
        }),
        new Log2gelf({
            level: 'error',
            host: '192.168.0.15',
            port: 12201,
            protocol: 'tls'
        })
    ]
});

Note that if you wish to handle Exceptions, as Winston automatically exits after an exception, you have to disable the exit behaviour to let Log2gelf enough time to send the log across the network.

  const logger = winston.createLogger({
    exitOnError: false, // disable default winston exit
    transports: [
        new winston.transports.Console({
            level: 'info',
            handleExceptions: true
        }),
        new Log2gelf({
            level: 'error',
            host: '192.168.0.15',
            port: 12201,
            protocol: 'tls',
            handleExceptions: true, // handle exception within Log2gelf
            exitOnError: true, // exit after exception has been sent
            exitDelay: 1000 // leave Log2gelf 1sec to send the message
        })
    ]
});

If used in a script where the process has to naturally exit after its execution, the connection has to be closed (as a db connection would have to) if TCP socket is used. It should be done like so:

const log2gelf = logger.transports.find(transport => transport.name === 'log2gelf');
logger.end = log2gelf.end;

Options

  • name: Transport name
  • hostname: The name of this host (default: os.hostname())
  • host: The GELF server address (default: 127.0.0.1)
  • port: The GELF server port (default: 12201)
  • protocol: Protocol used to send data (tcp, tls [TCP over TLS], http or https). (default: tcp)
  • protocolOptions: Socket connect options. See net.socket.connect or tls.connect for available options.
  • reconnect: Number of tcp reconnect attempts (default 0, 0 for none, -1 for infinite)
  • wait: Milliseconds to wait between reconnect attempts (default 1000)
  • level: Level of messages this transport should log. See winston levels (default: info)
  • silent: Boolean flag indicating whether to suppress output. (default: false)
  • handleExceptions: Boolean flag, whether to handle uncaught exceptions. (default: false)
  • exitOnerror: Will exit after x ms (2 sec by default) if Winston exitOnError is set to false if an exception is caught
  • exitDelay: Specify the exit delay in ms for exitOnerror option. (default 2000ms)
  • service: as facility is deprecated, service describes what kind of "service" this is (like MySQLd or Apache2). (default: nodejs)
  • environment: the environment on which your service is running. (default: development)
  • release: the version of your service (e.g. 1.0.0).
  • _foo: any underscore-prefixed custom option will be passed as is to the server.

Contributing

There's sure room for improvement, so feel free to hack around and submit PRs! Please just follow the style of the existing code, which is Airbnb's style with minor modifications.

To maintain things clear and visual, please follow the git commit template.

winston-log2gelf's People

Contributors

buzut avatar cxcorp avatar dependabot[bot] avatar brijtosuccess avatar fnj5 avatar pepakriz avatar doitlikepruett avatar mihaiblaga89 avatar crashoz avatar

Watchers

James Cloos avatar  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.