This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

hbp-fluentd-logger

1.0.2 • Public • Published

HBP FluentD Logger

A thin wrapper for repeated HTTP(S) calls. Stand in replacement for all console.log etc calls to a central logging service.

Written for HTTP(S) interface with fluentd

Example usage

// server.js
const { Logger } = require('hbp-fluentd-logger')

const {
  APPLICATION_NAME,
  FLUENT_PROTOCOL,
  FLUENT_HOST,
  FLUENT_PORT
} = process.env

const name = APPLICATION_NAME || 'my application name'
const protocol = FLUENT_PROTOCOL || 'https'
const host = FLUENT_HOST || 'localhost'
const port = FLUENT_PORT || 24224

const log = new Logger(name, {
  protocol,
  host,
  port
})

const handleRequestCallback = (err, resp, body) => {
  if (err) {
    process.stderr.write(`fluentD logging failed\n`)
    process.stderr.write(err.toString())
    process.stderr.write('\n')
  }

  if (resp && resp.statusCode >= 400) {
    process.stderr.write(`fluentD logging responded error\n`)
    process.stderr.write(resp.toString())
    process.stderr.write('\n')
  }
}

const emitInfo = message => log.emit('info', { message }, handleRequestCallback)

const emitWarn = message => log.emit('warn', { message }, handleRequestCallback)

const emitError = message => log.emit('error', { message }, handleRequestCallback)

console.log('starting fluentd logging')

console.log = function () {
  emitInfo([...arguments])
}
console.warn = function () {
  emitWarn([...arguments])
}
console.error = function () {
  emitError([...arguments])
}

License

MIT

/hbp-fluentd-logger/

    Package Sidebar

    Install

    npm i hbp-fluentd-logger

    Weekly Downloads

    2

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    3.07 kB

    Total Files

    4

    Last publish

    Collaborators

    • pandamakes