Coder Social home page Coder Social logo

winston-papertrail's Introduction

winston-papertrail Build Status NPM version

A Papertrail transport for winston.

Installation

Installing npm (node package manager)

  $ curl http://npmjs.org/install.sh | sh

Installing winston-papertrail

  $ npm install winston
  $ npm install winston-papertrail

There are a few required options for logging to Papertrail:

  • host: FQDN or IP Address of the Papertrail Service Endpoint
  • port: The Endpoint TCP Port

Usage

  var winston = require('winston');

  //
  // Requiring `winston-papertrail` will expose
  // `winston.transports.Papertrail`
  //
  require('winston-papertrail').Papertrail;

  var winstonPapertrail = new winston.transports.Papertrail({
	host: 'logs.papertrailapp.com',
	port: 12345
  })
  
  winstonPapertrail.on('error', function(err) {
	// Handle, report, or silently ignore connection errors and failures
  });

  var logger = new winston.Logger({
	transports: [winstonPapertrail]
  });

  logger.info('this is my message');

There are a number of optional settings:

  • disableTls - set to true to disable TLS on your transport. Defaults to false
  • level - The log level to use for this transport, defaults to info
  • levels - A custom mapping of log levels strings to severity levels, defaults to the mapping of npm levels to RFC5424 severities
  • hostname - The hostname for your transport, defaults to os.hostname()
  • program - The program for your transport, defaults to default
  • facility - The syslog facility for this transport, defaults to daemon
  • logFormat - A function to format your log message before sending, see below
  • colorize - Enable colors in logs, defaults to false
  • inlineMeta - Inline multi-line messages, defaults to false
  • handleExceptions - Tell this Transport to handle exceptions, defaults to false
  • flushOnClose - Flush any queued logs prior to closing/exiting
  • depth - max depth for objects dumped by NodeJS util.inspect

There are also a number of settings for connection failure and retry behavior

  • attemptsBeforeDecay - How many retries should be attempted before backing off, defaults to 5
  • maximumAttempts - How many retries before disabling buffering, defaults to 25
  • connectionDelay - How long between backoff in milliseconds, defaults to 1000
  • maxDelayBetweenReconnection - The maximum backoff in milliseconds, defaults to 60000
  • maxBufferSize - The maximum size of the retry buffer, in bytes, defaults to 1048576

Advanced Usage

For more some advanced logging, you can take advantage of custom formatting for Papertrail:

  var winston = require('winston');

  //
  // Requiring `winston-papertrail` will expose
  // `winston.transports.Papertrail`
  //
  require('winston-papertrail').Papertrail;

  var logger = new winston.Logger({
  	transports: [
  		new winston.transports.Papertrail({
  			host: 'logs.papertrailapp.com',
  			port: 12345,
  			logFormat: function(level, message) {
  			    return '<<<' + level + '>>> ' + message;
  			}
  		})
  	]
  });

  logger.info('this is my message');

Transport Events

The Papertrail transport is also capable of emitting events for error and connect so you can log to other transports:

var winston = require('winston'),
	Papertrail = require('winston-papertrail').Papertrail;

var logger,
	consoleLogger = new winston.transports.Console({
		level: 'debug',
		timestamp: function() {
			return new Date().toString();
		},
		colorize: true
	}),
	ptTransport = new Papertrail({
		host: 'logs.papertrailapp.com',
		port: 12345,
		hostname: 'web-01',
		level: 'debug',
		logFormat: function(level, message) {
			return '[' + level + '] ' + message;
		}
	});

ptTransport.on('error', function(err) {
	logger && logger.error(err);
});

ptTransport.on('connect', function(message) {
	logger && logger.info(message);
});

var logger = new winston.Logger({
	levels: {
		debug: 0,
		info: 1,
		warn: 2,
		error: 3
	},
	transports: [
		ptTransport,
		consoleLogger
	]
});

logger.info('this is my message ' + new Date().getTime());

Colorization

The winston-papertrail transport supports colorization with winston. Currently, the ANSI codes used for escape sequences are part of the search index, so please be advised when using colorization.

var winston = require('winston'),
    Papertrail = require('winston-papertrail').Papertrail;

var logger = new winston.Logger({
    transports: [
        new Papertrail({
            host: 'logs.papertrailapp.com',
            port: 12345, // your port here
            colorize: true
        })
    ]
});

logger.info('Hello from colorized winston', logger);

Closing the transport

As of v0.1.3 winston-papertrail transport supports closing the transport (and the underlying TLS connection) via the Winston.Transport close method. Thus, you can enable scenarios where your transport automatically closes when you close the winston logger.

var winston = require('winston'),
    Papertrail = require('winston-papertrail').Papertrail;

pt = new Papertrail({
    host: 'logs.papertrailapp.com',
    port: 12345 // your port here
});

var logger = new winston.Logger({
    transports: [ pt ]
});

pt.on('connect', function () {
    logger.info('logging before I close');
    logger.close(); // this closes the underlying connection in the Papertrail transport
});

Author: Ken Perkins

winston-papertrail's People

Contributors

andyburke avatar brycekahle avatar c4milo avatar coreybutler avatar crito avatar eric avatar gergderkson avatar guillegette avatar jahqueel avatar kenperkins avatar mathisonian avatar miroradenovic avatar troy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winston-papertrail's Issues

Should colorize log level AFTER logFormat

With the currently flow, certain things are not possible, while colorizing with a log format.

e.g.

new winston.transports.Papertrail({
    host:      process.env.LOG_HOST,
    port:      process.env.LOG_PORT,
    colorize:  true,
    logFormat: function(level, message) {
        return level.toUpperCase() + ' | ' + message;
    },
    program:   os.hostname()
})

as the colorized level, is uppercased as well, becoming [32MINFO[39M instead of [32mINFO[39m

Logging anything logs twice

I am using winston and node.js and when I log anything I get two log lines.

The first line is what I logged the second is a line with just { } in it.

logging

Variable Program String

I'm looking to pass an additional string along with each log message so as to dynamically define the program. Any suggestions how could I go about doing that?

Example:

var winston = require('winston');
require('winston-papertrail').Papertrail;

var winstonPapertrail = new winston.transports.Papertrail({
    host: 'logs12345.papertrailapp.com',
    port: 12345,
    program: 'PINEAPPLES_ARE_BLUE'
});

var logger = new winston.Logger({ transports: [winstonPapertrail] });

logger.info('This is my log message', 'PINEAPPLES_ARE_BLUE');

Thank you

Struggled trying to get integration with Papertrail using bunyan...tried this and was a cinch, plus the output was better. Appreciate the work.

Exception on stream timeout

Just got a strange restart on a server and, when I looked in the logs, it was due to a timeout on the winston-papertrail<>papertrail stream. I think this is solved by #46 on line 170

The stacktrace (with longjohn enabled):

  stack:
   [ 'Error: connect ETIMEDOUT',
     '    at errnoException (net.js:901:11)',
     '    at Object.afterConnect [as oncomplete] (net.js:892:19)',
     '---------------------------------------------',
     '    at Socket.Readable.on (_stream_readable.js:689:33)',
     '    at CleartextStream.connectStream (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:173:24)',
     '    at CleartextStream.EventEmitter.emit (events.js:117:20)',
     '    at _stream_readable.js:920:16',
     '    at process._tickCallback (node.js:415:13)',
     '---------------------------------------------',
     '    at CleartextStream.Readable.on (_stream_readable.js:689:33)',
     '    at wireStreams (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:152:29)',
     '    at Socket.<anonymous> (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:170:21)',
     '    at Socket.g (events.js:180:16)',
     '    at Socket.EventEmitter.emit (events.js:92:17)',
     '    at Object.afterConnect [as oncomplete] (net.js:883:10)',
     '---------------------------------------------',
     '    at Socket.connect (net.js:800:10)',
     '    at Object.exports.connect.exports.createConnection (net.js:94:35)',
     '    at CleartextStream.connectStream (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:162:34)',
     '    at CleartextStream.EventEmitter.emit (events.js:117:20)',
     '    at _stream_readable.js:920:16',
     '    at process._tickCallback (node.js:415:13)',
     '---------------------------------------------',
     '    at CleartextStream.Readable.on (_stream_readable.js:689:33)',
     '    at wireStreams (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:152:29)',
     '    at Socket.<anonymous> (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:170:21)',
     '    at Socket.g (events.js:180:16)',
     '    at Socket.EventEmitter.emit (events.js:92:17)',
     '    at Object.afterConnect [as oncomplete] (net.js:883:10)',
     '---------------------------------------------',
     '    at Socket.connect (net.js:800:10)',
     '    at Object.exports.connect.exports.createConnection (net.js:94:35)',
     '    at CleartextStream.connectStream (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:162:34)',
     '    at CleartextStream.EventEmitter.emit (events.js:117:20)',
     '    at _stream_readable.js:920:16',
     '    at process._tickCallback (node.js:415:13)',
     '---------------------------------------------',
     '    at CleartextStream.Readable.on (_stream_readable.js:689:33)',
     '    at wireStreams (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:152:29)',
     '    at Socket.<anonymous> (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:170:21)',
     '    at Socket.g (events.js:180:16)',
     '    at Socket.EventEmitter.emit (events.js:92:17)',
     '    at Object.afterConnect [as oncomplete] (net.js:883:10)',
     '---------------------------------------------',
     '    at Socket.connect (net.js:800:10)',
     '    at Object.exports.connect.exports.createConnection (net.js:94:35)',
     '    at CleartextStream.connectStream (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:162:34)',
     '    at CleartextStream.EventEmitter.emit (events.js:117:20)',
     '    at _stream_readable.js:920:16',
     '    at process._tickCallback (node.js:415:13)',
     '---------------------------------------------',
     '    at CleartextStream.Readable.on (_stream_readable.js:689:33)',
     '    at wireStreams (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:152:29)',
     '    at Socket.<anonymous> (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:170:21)',
     '    at Socket.g (events.js:180:16)',
     '    at Socket.EventEmitter.emit (events.js:92:17)',
     '    at Object.afterConnect [as oncomplete] (net.js:883:10)',
     '---------------------------------------------',
     '    at Socket.connect (net.js:800:10)',
     '    at Object.exports.connect.exports.createConnection (net.js:94:35)',
     '    at CleartextStream.connectStream (/home/nodeapps/my-node-app/node_modules/winston-papertrail/lib/winston-papertrail.js:162:34)',
     '    at CleartextStream.EventEmitter.emit (events.js:117:20)',
     '    at _stream_readable.js:920:16',
     '    at process._tickCallback (node.js:415:13)' ] }

Node may ship without TLS root CAs (Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE)

A user reported upgrading to Node.js 0.10 and starting to receive this error:

Mar 20 21:20:23 - [info]: Reconnecting logging...
Mar 20 21:20:23 - [info]: Attempting to connect to Papertrail
Mar 20 21:20:23 - [error]: Error with TLS connection [Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE]

This user tried this PPA distribution as well as compiling from source. They reported that 0.8 was working fine.

From what I can tell, the cause is that Node.js ships an openssl which (intentionally) doesn't include any root CA files. Here's more. The tls.connect method uses these root CA files.

I don't have an easy way to verify that this is the cause or that it was in fact a change from 0.8 to 0.10 (rather than, say, an individual package maintainer's decision). Opening this in case others see the same error and want to comment further.

There's not necessarily anything Node or winston-papertrail can or should do here, since distributing a cert chain gets ugly fast (and the same problem will affect anything else that tries to make an outbound TLS connection, not just winston-papertrail).

Support for Winston 3.0?

Winston 3.0 is going to be released soon. It has some breaking changes for transports which makes winston-papertrail incompatible.

For example, log is now called with a single info object containing message, level instead of a few separate variables.

@kenperkins or @troy would you be so kind to adjust the plugin for the new winston version?

Transport "error" callback is firing

The connection seems to be falling off for long-lived connections.

    const winstonPapertrail = new winston.transports.Papertrail(options)
    this.logger = new winston.Logger({
      levels: this.options.levels,
      transports: [winstonPapertrail]
    })

    winstonPapertrail.on('error', (err) => {
      this.emit('error', new Error('INSTANTIATION_FAILED', err))
    })

Error output to stdout:

There was a problem (Error: INSTANTIATION_FAILED) in papertrail and it has been destroyed.

Any ideas on how to avoid this? or reconnect automatically?

Additional line in papertrail after logged message

var winston = require('winston');

  //
  // Requiring `winston-papertrail` will expose
  // `winston.transports.Papertrail`
  //
  require('winston-papertrail').Papertrail;

  var logger = new winston.Logger({
    transports: [
        new winston.transports.Papertrail({
            host: 'logs.papertrailapp.com',
            port: 12345,
            logFormat: function(level, message) {
                return '<<<' + level + '>>> ' + message;
            }
        })
    ]
  });

  logger.info('this is my message');

This code produces

May 12 17:22:13 localhost default:  <<<info>>> this is my message 
May 12 17:22:13 localhost default:  <<<info>>>     {} 

in Papertrail.

Winston-Papertrail: 0.1.2
Winston: 0.7.1

If writing to buffer, winston 'logging' event will never be emitted

On line 397 we attempt to write to the stream and invoke the winston-provided callback on response. However, if the stream is unavailable and we are writing to buffer on line 400 the callback is simply dropped and will never be invoked.

This results in the 'logging' event for the winston logger never firing for that transport and any buffered messages. To the end user it appears as though the messages themselves have been dropped, when in reality they have simply been buffered.

A potential relatively simple solution would be to simply retain references to the callbacks for buffered messages, and invoke these when the buffer has been successfully processed. If desired, I could make an attempt at implementing this change.

README didn't work

I wasn't able to get the sample code to work. But it did work if I use winston.add with Papertrail and my options.

winston = require('winston');
require('winston-papertrail').Papertrail;
winston.add(winston.transports.Papertrail, {
  host: 'logs.papertrailapp.com',
  port: '12345'
});
winston.debug('sugarbuns')

Unable to log "error" objects using this transport

For whatever reason, error objects in node ~10 don't have keys, causing the log function to reject them as metadata, I'm proposing a small change:

from:

    if  (meta && typeof meta === 'object' && Object.keys(meta).length === 0) {
        meta = false;
    }

to:

    if  (meta && typeof meta === 'object' && (Object.keys(meta).length === 0)
        && (!util.isError(meta)))
    {
        meta = false;
    }

I'll submit a PR shortly,

Submitted PR #44

Thanks!
David

Glossy ReferenceError: formattedDate is not defined

My app is in strict mode. [email protected]

ReferenceError: formattedDate is not defined
web_1       |     at generateDate (/usr/src/app/node_modules/glossy/lib/glossy/produce.js:376:19)
web_1       |     at GlossyProducer.produce (/usr/src/app/node_modules/glossy/lib/glossy/produce.js:171:22)
web_1       |     at Papertrail.sendMessage (/usr/src/app/node_modules/winston-papertrail/lib/winston-papertrail.js:390:30)
web_1       |     at Papertrail.log (/usr/src/app/node_modules/winston-papertrail/lib/winston-papertrail.js:347:10)
web_1       |     at transportLog (/usr/src/app/node_modules/winston/lib/winston/logger.js:228:15)
web_1       |     at /usr/src/app/node_modules/winston/node_modules/async/lib/async.js:157:13
web_1       |     at _each (/usr/src/app/node_modules/winston/node_modules/async/lib/async.js:57:9)
web_1       |     at Object.async.each (/usr/src/app/node_modules/winston/node_modules/async/lib/async.js:156:9)
web_1       |     at Logger.log (/usr/src/app/node_modules/winston/lib/winston/logger.js:240:9)
web_1       |     at target.(anonymous function) [as info] (/usr/src/app/node_modules/winston/lib/winston/common.js:54:18)
web_1       |     at Log.self.(anonymous function) [as info] (/usr/src/app/node_modules/express-winston-middleware/index.js:305:31)
web_1       |     at ServerResponse.res.end (/usr/src/app/node_modules/express-winston-middleware/index.js:132:31)
web_1       |     at writeend (/usr/src/app/node_modules/express-session/index.js:266:14)
web_1       |     at ontouch (/usr/src/app/node_modules/express-session/index.js:348:11)
web_1       |     at tryCatcher (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/util.js:16:23)
web_1       |     at Promise.successAdapter [as _fulfillmentHandler0] (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/nodeify.js:22:30)
web_1       |     at Promise._settlePromise (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:566:21)
web_1       |     at Promise._settlePromise0 (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:614:10)
web_1       |     at Promise._settlePromises (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:693:18)
web_1       |     at Promise._fulfill (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:638:18)
web_1       |     at Promise._resolveCallback (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:432:57)
web_1       |     at Promise._settlePromiseFromHandler (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:524:17)
web_1       |     at Promise._settlePromise (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:569:18)
web_1       |     at Promise._settlePromise0 (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:614:10)
web_1       |     at Promise._settlePromises (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:693:18)
web_1       |     at Promise._fulfill (/usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/promise.js:638:18)
web_1       |     at /usr/src/app/node_modules/connect-mongo/node_modules/bluebird/js/release/nodeback.js:45:21
web_1       |     at handleCallback (/usr/src/app/node_modules/mongodb/lib/utils.js:120:56)

Most likely it has been fixed already squeeks/glossy@734b9c8 and you need to update dependency.

Callback not being fired

logger.log(
  'info',
  'Callback test',
  {
    reqid: 'aaaaaa-bbbbb-23321',
    details: {
      name: 'test',
    },
  },
  () => {
    console.log('callback fired');
  }
);

When I make this call, the callback function is not getting fired for some reason. I looked at the winston-papertrail code, and I can't find anything wrong with it. It passes the callback to stream.write() which looks good.

Prevents program from exiting

Noticed a peculiar issue in that any library that I included winston-papertrail in would never actually exit. Here is how to reproduce:

Put the following in test.js:

  var winston = require('winston');

  //
  // Requiring `winston-papertrail` will expose
  // `winston.transports.Papertrail`
  //
  require('winston-papertrail').Papertrail;

  var logger = new winston.Logger({
    transports: [
        new winston.transports.Papertrail({
            host: 'logs.papertrailapp.com',
            port: 12345
        })
    ]
  });

  logger.info('this is my message2');

Execute it with node test.js and the program will never exit. It will correctly log your message to Papertrail.

This behavior doesn't exist with, say, just the default Console logger.

This bug is reproduceable on 0.1.1 and 0.1.2, using winston 0.6.2. Also reproducable using 0.1.2 and the latest winston 0.7.1. I'm using node 0.8.14.

possible EventEmitter memory leak detected

I got this strange error in my log file, is it related to this module ?
It is not the full trace but these lines keep repeating.

2014-10-22T09:30:31.326261002Z (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
2014-10-22T09:30:31.330676223Z Trace
2014-10-22T09:30:31.330676223Z at EventEmitter.addListener (events.js:160:15)
2014-10-22T09:30:31.330676223Z at Readable.on (_stream_readable.js:689:33)
2014-10-22T09:30:31.330676223Z at Readable.pipe (_stream_readable.js:491:8)
2014-10-22T09:30:31.330676223Z at pipe (tls.js:1409:18)
2014-10-22T09:30:31.330676223Z at exports.connect (tls.js:1355:19)
2014-10-22T09:30:31.330676223Z at Socket. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:136:29)
2014-10-22T09:30:31.330676223Z at g (events.js:180:16)
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Socket.connect (net.js:800:10)
2014-10-22T09:30:31.330676223Z at exports.connect.exports.createConnection (net.js:94:35)
2014-10-22T09:30:31.330676223Z at connectStream (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:134:27)
2014-10-22T09:30:31.330676223Z at CleartextStream. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:176:15)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:117:20)
2014-10-22T09:30:31.330676223Z at _stream_readable.js:920:16
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Readable.on (_stream_readable.js:689:33)
2014-10-22T09:30:31.330676223Z at Socket. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:175:23)
2014-10-22T09:30:31.330676223Z at g (events.js:180:16)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:92:17)
2014-10-22T09:30:31.330676223Z at afterConnect (net.js:883:10)
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Socket.connect (net.js:800:10)
2014-10-22T09:30:31.330676223Z at exports.connect.exports.createConnection (net.js:94:35)
2014-10-22T09:30:31.330676223Z at connectStream (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:134:27)
2014-10-22T09:30:31.330676223Z at CleartextStream. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:176:15)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:117:20)
2014-10-22T09:30:31.330676223Z at _stream_readable.js:920:16
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Readable.on (_stream_readable.js:689:33)
2014-10-22T09:30:31.330676223Z at Socket. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:175:23)
2014-10-22T09:30:31.330676223Z at g (events.js:180:16)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:92:17)
2014-10-22T09:30:31.330676223Z at afterConnect (net.js:883:10)
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Socket.connect (net.js:800:10)
2014-10-22T09:30:31.330676223Z at exports.connect.exports.createConnection (net.js:94:35)
2014-10-22T09:30:31.330676223Z at connectStream (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:134:27)
2014-10-22T09:30:31.330676223Z at CleartextStream. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:176:15)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:117:20)
2014-10-22T09:30:31.330676223Z at _stream_readable.js:920:16
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Readable.on (_stream_readable.js:689:33)
2014-10-22T09:30:31.330676223Z at Socket. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:175:23)
2014-10-22T09:30:31.330676223Z at g (events.js:180:16)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:92:17)
2014-10-22T09:30:31.330676223Z at afterConnect (net.js:883:10)
2014-10-22T09:30:31.330676223Z ---------------------------------------------
2014-10-22T09:30:31.330676223Z at Socket.connect (net.js:800:10)
2014-10-22T09:30:31.330676223Z at exports.connect.exports.createConnection (net.js:94:35)
2014-10-22T09:30:31.330676223Z at connectStream (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:134:27)
2014-10-22T09:30:31.330676223Z at CleartextStream. (/src/node_modules/winston-papertrail/lib/winston-papertrail.js:176:15)
2014-10-22T09:30:31.330676223Z at EventEmitter.emit (events.js:117:20)
2014-10-22T09:30:31.330676223Z at _stream_readable.js:920:16
2014-10-22T09:30:31.330676223Z ---------------------------------------------

Quota limit exceeded causes crash

Getting an upstream cannot connect error when we've exceeded our Papertrail quota. Did this type of error get caught in any release after 0.1.5?

Infrequent logging / connection errors

Our app writes infrequent logs to papertrail. Everything seemed to be working after testing however I noticed that we have a lot of errors in our file logs like the following with nothing written to Papertrail:

0|cluster  | Papertrail connection error:  { Error: read ECONNRESET
0|cluster  |     at _errnoException (util.js:1031:13)
0|cluster  |     at TLSWrap.onread (net.js:619:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

The keepalive is set, however if the connection times out should it automatically reconnect or must this be done manually? If so what is the proper way to re-establish the connection within the transport?

Move to papertrail org?

So the reality is I don't have much dev bandwidth at this point, and I worry it's impacting users of Papertrail. So I'm wondering if we should entertain moving this to the Papertrail org so they can more directly solicit maintainers. @troy what do you think?

Memory leak / endless loop

Using util.inspect without depth limit can cause memory leak / endless flooding in case an object has circular dependency

lines 335, 331 and 338

if (typeof(output) !== 'string') {
     output = util.inspect(output, false, null, self.colorize);
    }

    if (meta) {
        if (typeof meta !== 'object') {
            output += ' ' + meta;
        }
        else if (meta) {
            if (this.inlineMeta) {
                output += ' ' + util.inspect(meta, false, null, self.colorize).replace(/[\n\t]\s*/gm, " ");
            }
            else {
                output += '\n' + util.inspect(meta, false, null, self.colorize);

When Papertrail refuses connection you b/c you reached your max

So I just learned the REALLY hard way that if Papertrail reaches it's max and no longer collects data it will refuse a connection from your servers. That will in turn throw an error with this library:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: connect ECONNREFUSED
    at exports._errnoException (util.js:746:11)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)

It took hours to track down this issue and finally realize what it was. This package should have better error tracking for when a connection with Papertrail can't be made. Took down a production app for an hour. cries

TypeError: Cannot call method 'match' of undefined

Not sure where this error originates, but it pops up every so often. Any thoughts?

/var/app/current/node_modules/divshot-logger/node_modules/winston/lib/winston/config.js:26
  } else if (allColors[level].match(/\s/)) {
                              ^
TypeError: Cannot call method 'match' of undefined
    at Object.config.colorize (/var/app/current/node_modules/divshot-logger/node_modules/winston/lib/winston/config.js:26:31)
    at Papertrail.sendMessage (/var/app/current/node_modules/divshot-logger/node_modules/winston-papertrail/lib/winston-papertrail.js:347:68)
    at Papertrail.log (/var/app/current/node_modules/divshot-logger/node_modules/winston-papertrail/lib/winston-papertrail.js:299:10)
    at Transport.logException (/var/app/current/node_modules/divshot-logger/node_modules/winston/lib/winston/transports/transport.js:124:8)
    at logAndWait (/var/app/current/node_modules/divshot-logger/node_modules/winston/lib/winston/logger.js:631:15)
    at /var/app/current/node_modules/async/lib/async.js:125:13
    at Array.forEach (native)
    at _each (/var/app/current/node_modules/async/lib/async.js:46:24)
    at Object.async.each (/var/app/current/node_modules/async/lib/async.js:124:9)
    at Logger._uncaughtException (/var/app/current/node_modules/divshot-logger/node_modules/winston/lib/winston/logger.js:654:9)

Logging from function that is called repeatedly

I've got a node.js process that repeatedly maps over long-running functions. I'm trying to log that into Papertrail but I only get the first log showing up in Papertrail. It's a brand-new instance of Papertrail and I've checked that there are no log filters applied.

Two scenarios:

  1. If I control-c the process, I only get the first log in Papertrail (but all intermediate logs still go to the console)
  2. If I let the process finish, I get all of the backed-up logs showing up in Papertrail. But that defeats the purpose of seeing what's going one while it's running.

The function called repeatedly is displayProgress() shown below.

import winston from 'winston'
require('winston-papertrail').Papertrail

const winstonConsole = new winston.transports.Console()
const winstonPapertrail = new winston.transports.Papertrail({
  host: 'logsx.papertrailapp.com',
  port: xxxx,
  flushOnClose: true,
})

const logger = new winston.Logger({
  transports: [winstonConsole, winstonPapertrail],
})

export function displayProgress() {
  const message = `It's ${new Date()}`
  logger.info(message)

  // These don't fix the problem:
  // winstonPapertrail.on('connect', (message) => {
  //   logger && logger.info(message)
  // })
  //
  // winstonPapertrail.on('error', (err) => {
  //   logger && logger.error(err)
  // })
}

It's like it's storing it and then flushing it only at the end. I've tried flushOnClose as true and as false but neither solves the problem. Does the library not support this? Or is there a setting that I'm missing?

Thank you

What if meta is not an object?

If I understand it correctly, meta can be either an object or a string, however in case of a string, line 260 will fail with the error TypeError: Object.keys called on non-object.

Process doesn't exit, just by instantiating

When I instantiate a papertrail transport, the process doesn't exit anymore. I don't even have to add it to the transports. And if I add it to transports and call close on the winston object, this happens:

node_modules\winston\lib\winston\config.js:30
  else if (allColors[level].match(/\s/)) {
                           ^

TypeError: Cannot read property 'match' of undefined
    at Object.config.colorize (node_modules\winston\lib\winston\config.js:30:28)
    at Papertrail.sendMessage (node_modules\winston-papertrail\lib\winston-papertrail.js:349:68)
    at Papertrail.log (node_modules\winston-papertrail\lib\winston-papertrail.js:301:10)
    at Transport.logException (node_modules\winston\lib\winston\transports\transport.js:134:8)
    at logAndWait (node_modules\winston\lib\winston\logger.js:643:15)
    at node_modules\async\lib\async.js:157:13
    at _each (node_modules\async\lib\async.js:57:9)
    at Object.async.each (node_modules\async\lib\async.js:156:9)
    at Logger._uncaughtException (node_modules\winston\lib\winston\logger.js:666:9)
    at emitOne (events.js:96:13)```

which seems to be related to Transport.logException, and when I set handleExceptions to false, I get

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: write after end
    at writeAfterEnd (_stream_writable.js:166:12)
    at TLSSocket.Writable.write (_stream_writable.js:217:5)
    at TLSSocket.Socket.write (net.js:643:40)
    at TLSSocket.onConnected (node_modules\winston-papertrail\lib\winston-papertrail.js:228:25)
    at TLSSocket.g (events.js:286:16)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:185:7)
    at TLSSocket.<anonymous> (_tls_wrap.js:1076:14)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:185:7)

And finally, similar to #52, if I introduce a one second delay before calling close, it seems to work, but an explicit call to close is required. Do you always have to close the connection as soon as a Papertrail object exists? Something definitely remains in the event loop, since I cannot use exit or beforeExit to close it automatically.

Unable to log "error" objects using this transport

For whatever reason, error objects in node ~10 don't have keys, causing the log function to reject them as metadata, I'm proposing a small change:

from:

    if  (meta && typeof meta === 'object' && Object.keys(meta).length === 0) {
        meta = false;
    }

to:

    if  (meta && typeof meta === 'object' && (Object.keys(meta).length === 0)
        && (!util.isError(meta)))
    {
        meta = false;
    }

I'll submit a PR shortly,

Thanks!
David

Clarify winston compatibility

I've been using winston-papertrail with winston 1.1.2 for some time, working fine.
However, a module requiring winston 2.1.1 resulted in winston.transports not being assigned Papertrail as a transport. It seems to work to use the returned constructor from winston-papertrail directly, it seems only the injection of winston.transports.Papertrail as the constructor seems to fail.

I saw another issue about winston 3.0 breaking changes, but is it known/expected that winston-papertrail also breaks with 2.x?

Error when logging non-strings

If I try and send an array to the logs (using the latest .4 release), I get an error:

winston-papertrail/lib/winston-papertrail.js:201:25

[error] TypeError: Object 8,7 has no method 'split'

What is the best way to deal with this?

Error events for ECONNREFUSED

Recently ran into a case were the connection refused because of a log limit being reached. Are there errors emitted by the module that would allow me to catch that error?

Pass meta data into logFormat()

Currently, logFormat() input arguments are level and message, and I wonder if meta data can also be passed into the function for reformatting.

I use meta data to identify the log from different components of my system, so it may not be the best way to display if it is only printed at the end of the log message for meta data. Winston's file and console transport also provide meta data for the log formatter.

Error when using with winston 0.7.1

The package.json of our application has both dependencies to [email protected] and [email protected].

I am getting the following npm errors when running npm install:

➜  configengine git:(master) ✗ npm install
[...]
npm ERR! peerinvalid The package winston does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants [email protected]

npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/nherment/workspace/nimbus/configengine
npm ERR! node -v v0.10.3
npm ERR! npm -v 1.2.17
npm ERR! code EPEERINVALID
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/nherment/workspace/nimbus/configengine/npm-debug.log
npm ERR! not ok code 0

It's not blocking me as npm installs winston and winston-papertrail regardless of the error.

only log `meta` if present

Whenever I log anything I always get an extra line in the papertrail logs containing {}. Looks like the lib is just checking for if (meta). It meta is an object it should also check for Object.keys(meta).length > 0

Emitting 'error'-event

There is this line 228 in the main file in onErrored:

self.emit('error', err);

As the error is emitted, this causes the whole process to end, if the error isn't listened on elsewhere. This can lead to server crashes if Papertrail cannot be connected to. I thought maybe this should be mentioned in the docs. :)

logFormat, message incorrect formated

Guy can someone tell me. Had update the winston-papertrail to version 1.0.5 (winston version 3.0.0), and saw interesting thing. 2nd parameter 'message' that came in logFormat, formated like this, example:
'Some message { message: 'Some message', level: 'info' }'
Should it be like this, or not? If yes, how to work with it?
After investigation I found in file /lib/winston-papertrail.js, line:325 (var output = msg;)
That set this duplication msg.

`var output = msg;

// If we don't have a string for the message,
// lets transform it before moving on
if (typeof(output) !== 'string') {
    output = util.inspect(output, false, self.depth, self.colorize);
}

if (meta) {
    if (typeof meta !== 'object') {
        output += ' ' + meta;
    }
    else if (meta) {
        if (this.inlineMeta) {
            output += ' ' + util.inspect(meta, false, self.depth, self.colorize).replace(/[\n\t]\s*/gm, " ");
        }
        else {
            output += '\n' + util.inspect(meta, false, self.depth, self.colorize);
        }
    }
}

this.sendMessage(this.hostname, this.program, level, output, callback);`

How logs should looks like?
How work with colorize? It doesn't work for me.
Maybe someone can share best practice.

Would be apriciate for any help.

Connection error

I'm having a connection problem while trying to implement the basic winston-papertrail config.
Here is my trace :
Papertrail connection error: TypeError: net.createConnection is not a function
at connectStream (winston-papertrail.js:211)
at new ./node_modules/winston-papertrail/lib/winston-papertrail.js.exports.Papertrail (winston-papertrail.js:158)

Seems like a missing dependency maybe?
npm install net didn't solve it

Node Process Won't exit

I'm testing the winston-papertrail with this simple code:

var winston = require('winston');
require('winston-papertrail').Papertrail;
var tr = new winston.transports.Papertrail({
  host: 'my-server.papertrailapp.com', // this is actually the right host
  port: 94573, // this is actually the right port
});

var Logger = new winston.Logger({
  transports: [] // <--- yes, not an error, I'm NOT adding the transport to winston
});
Logger.info("Hello world!!! " + new Date().getTime());

If I run this code the node process won't exit because of the connection to Papertrail server.
Is there any way to force close the pending connection?

Cannot flush logs before process ends

I have noticed that when a process ends, not all the logs are written because they are still in the buffer. File transport has a flush event you can hook on to prevent this. This transport does not offer the same, so I have had to do something like this...

//allow papertrail to flush the buffer
setTimeout(() => {
    logger.info('lambda#handler: success');
    context.succeed('success');
}, 1000);

winston.handleExceptions submits 'false' to papertrail.

Hi,
I'm trying to use winston-papertrail to log nodejs/express unhandled exceptions but they show up as "false" in papertrail.
Code snippet:

var winston = require('winston');
winston.handleExceptions(
  new winston.transports.Papertrail({
        host: 'xxx',
        port: xxx,
        hostname: 'xxx',
        inlineMeta: true
    })            
);

Then I throw an exception without catching it, like this:

throw Error('boo');

After spending some time looking into it I could find out that it looks like "level" is being passed as undefined into:

Papertrail.prototype.sendMessage = function (hostname, program, level, message) {

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.