Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

winston-papertrail

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-papertrail - npm Package Compare versions

Comparing version 0.0.6 to 0.1.0

.idea/dictionaries/kenn5998.xml

7

changelog.md

@@ -0,1 +1,8 @@

# v0.1.0 #
- Removed the levelDecorators option in favor of a format function
- Added a `connected` event for Papertrail
- Switched to jsdoc format
- Updated to winston 0.6.x dependency
- Added more examples to README
# v0.0.6 #

@@ -2,0 +9,0 @@ - Handle when logging a null or non-string value, Fix for issue #5

114

lib/winston-papertrail.js
/*
* winston-papertrail.js:
*
* Transport for logging to Papertrail Service
* (Special thanks to Charlie Robbins)
* www.papertrailapp.com
*
* (C) 2012 Ken Perkins
* (C) 2013 Ken Perkins
* MIT LICENCE

@@ -17,6 +17,40 @@ *

//
// ### function Papertrail (options)
// Constructor for the Papertrail transport object.
//
/**
* Papertrail class
*
* @description constructor for the Papertrail transport
*
* @param {object} options options for your papertrail transport
*
* @param {string} options.host host for papertrail endpoint
*
* @param {Number} options.port port for papertrail endpoint
*
* @param {string} [options.hostname] name for the logging hostname in Papertrail
*
* @param {string} [options.program] name for the logging program
*
* @param {string} [options.level] log level for your transport (info)
*
* @param {Function} [options.logFormat] function to format your log message before sending
*
* @param {Number} [options.attemptsBeforeDecay] how many reconnections should
* be attempted before backing of (5)
*
* @param {Number} [options.maximumAttempts] maximum attempts before
* disabling buffering (25)
*
* @param {Number} [options.connectionDelay] delay between
* reconnection attempts in ms (1000)
*
* @param {Boolean} [options.handleExceptions] passed to base Transport (false)
*
* @param {Number} [options.maxDelayBetweenReconnection] when backing off,
* what's the max time between
* reconnections (ms)
*
* @param {Boolean} [options.inlineMeta] inline multi-line messages (false)
*
* @type {Function}
*/
var Papertrail = exports.Papertrail = function(options) {

@@ -42,5 +76,6 @@

// Papertrail enables alerts on search matching. Prodiving a decorator for the level
// makes these searches more specific
self.levelDecorators = options.levelDecorators || ['[', ']'];
// Format your log messages prior to delivery
self.logFormat = options.logFormat || function(level, message) {
return level + ' ' + message;
}

@@ -136,2 +171,4 @@ // Number of attempts before decaying reconnection

self.emit('connect', 'Connected to Papertrail at ' + self.host + ':' + self.port);
// Did we get messages buffered

@@ -158,11 +195,21 @@ if (self.buffer) {

//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
/**
* Papertrail.log
*
* @description Core logging method exposed to Winston. Metadata is optional.
*
* @param {String} level Level at which to log the message.
* @param {String} msg Message to log
* @param {String|object|Function} [meta] Optional metadata to attach
* @param {Function} callback
* @returns {*}
*/
Papertrail.prototype.log = function(level, msg, meta, callback) {
// make sure we handle when meta isn't provided
if (typeof(meta) === 'function' && !callback) {
callback = meta;
meta = '';
}
// If the logging buffer is disabled, drop the message on the floor

@@ -173,4 +220,3 @@ if (!this.loggingEnabled) {

var decoratedLevel = this.levelDecorators[0] + level + this.levelDecorators[1],
output = msg;
var output = msg;

@@ -197,3 +243,3 @@ // If we don't have a string for the message,

this.sendMessage(this.hostname, this.program, decoratedLevel, output);
this.sendMessage(this.hostname, this.program, level, output);

@@ -203,13 +249,16 @@ callback(null, true);

//
// ### function sendMessage (hostname, program, level, message)
// #### @hostname {string} Hostname of the source application.
// #### @program {string} Name of the source application
// #### @level {string} Log level to send
// #### @message {string} Actual log message
// Handles sending the message to the stream, or buffering if not
//
/**
* Papertrail.sendMessage
*
* @description sending the message to the stream, or buffering if not connected
*
* @param {String} hostname Hostname of the source application.
* @param {String} program Name of the source application
* @param {String} level Log level of the message
* @param {String} message The message to deliver
*/
Papertrail.prototype.sendMessage = function(hostname, program, level, message) {
var lines = [],
var self = this,
lines = [],
msg = '',

@@ -231,3 +280,3 @@ gap = '';

// don't send extra message if our message ends with a newline
if (lines[i].length == 0 && i == lines.length - 1) {
if ((lines[i].length === 0) && (i == lines.length - 1)) {
break;

@@ -244,4 +293,4 @@ }

program + ' ' +
level + ' ' +
gap + lines[i] + '\r\n';
self.logFormat(level, gap + lines[i])
+ '\r\n';
}

@@ -257,2 +306,3 @@

// Helper function for date formatting
function getDate() {

@@ -259,0 +309,0 @@ var d = new Date();

{
"name": "winston-papertrail",
"description": "A Papertrail transport for winston",
"version": "0.0.6",
"author": "Ken Perkins <ken@clipboard.com>",
"version": "0.1.0",
"author": "Ken Perkins <ken.perkins@rackspace.com>",
"repository": {

@@ -12,3 +12,3 @@ "type": "git",

"devDependencies": {
"winston": "0.4.x",
"winston": "0.6.x",
"vows": "0.5.x"

@@ -15,0 +15,0 @@ },

@@ -20,6 +20,11 @@ # winston-papertrail

There are a few required options for logging to Papertrail:
* __host:__ FQDN or IP Address of the Papertrail Service Endpoint
* __port:__ The TLS Endpoint TCP Port
## Usage
``` js
var winston = require('winston');
//

@@ -30,23 +35,97 @@ // Requiring `winston-papertrail` will expose

require('winston-papertrail').Papertrail;
winston.add(winston.transports.Papertrail, options);
var logger = new winston.Logger({
transports: [
new winston.transports.Papertrail({
host: 'logs.papertrailapp.com',
port: 12345
})
]
});
logger.info('this is my message');
```
There are a few required options for logging to Papertrail:
For more some advanced logging, you can take advantage of custom formatting for
Papertrail:
* __host:__ FQDN or IP Address of the Papertrail Service Endpoint
* __port:__ The TLS Endpoint TCP Port
``` js
var winston = require('winston');
Currently, the Papertrail transport only supports TLS logging.
//
// Requiring `winston-papertrail` will expose
// `winston.transports.Papertrail`
//
require('winston-papertrail').Papertrail;
``` js
// The minimal papertrail transport config
var papertrail = new (winston.transports.Papertrail)({
host: 'logs.papertrailapp.com',
port: '12345'
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');
```
The Papertrail transport is also capable of emitting events for `error` and `connect` so you can log to other transports:
``` js
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',
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());
```
Currently, the Papertrail transport only supports TLS logging.
#### Author: [Ken Perkins](http://blog.clipboard.com)
[0]: https://github.com/flatiron/winston

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc