winston-cloudwatch
Advanced tools
Comparing version
@@ -0,1 +1,6 @@ | ||
### 2.0.0 | ||
Update to Winston 3.0. Update dependencies. | ||
(thanks to @nfantone and @patrickrgaffney for the precious help) | ||
### 1.13.1 | ||
@@ -2,0 +7,0 @@ |
var winston = require('winston'), | ||
WinstonCloudWatch = require('../index'); | ||
WinstonCloudWatch = require('../index') | ||
@@ -7,8 +7,14 @@ | ||
// is CloudWatch | ||
winston.add(WinstonCloudWatch, { | ||
winston.add(new WinstonCloudWatch({ | ||
logGroupName: 'testing', | ||
logStreamName: 'first' | ||
}); | ||
logStreamName: 'another', | ||
awsRegion: 'us-east-1' | ||
})) | ||
var error = new Error('we are doooooomed!'); | ||
winston.error('error', error) | ||
var error = new Error('are we doooooomed?') | ||
winston.error({ message: error }) | ||
// or also | ||
var error = new Error('definitely.') | ||
winston.error(error) |
var winston = require('winston'), | ||
WinstonCloudWatch = require('../index'); | ||
var self = winston.add(WinstonCloudWatch, { | ||
var self = winston.add(new WinstonCloudWatch({ | ||
name: 'using-kthxbye', | ||
logGroupName: 'testing', | ||
logStreamName: 'first' | ||
}); | ||
logStreamName: 'another', | ||
awsRegion: 'us-east-1' | ||
})); | ||
@@ -12,4 +14,5 @@ winston.error('1'); | ||
// flushes the logs and clears setInterval | ||
self.transports.CloudWatch.kthxbye(function() { | ||
var transport = self.transports.find((t) => t.name === 'using-kthxbye') | ||
transport.kthxbye(function() { | ||
console.log('bye'); | ||
}); |
@@ -27,3 +27,3 @@ var winston = require('winston'); | ||
}, | ||
awsRegion: 'us-west-2', | ||
awsRegion: 'us-east-1', | ||
jsonMessage: true | ||
@@ -30,0 +30,0 @@ }) |
@@ -5,23 +5,34 @@ var winston = require('winston'), | ||
winston.transports.CloudWatch1 = WinstonCloudWatch; | ||
winston.transports.CloudWatch2 = WinstonCloudWatch; | ||
const logger = winston.createLogger({ | ||
transports: [ | ||
new WinstonCloudWatch({ | ||
name: 'first-stream', | ||
logGroupName: 'testing', | ||
logStreamName: 'first', | ||
awsRegion: 'us-east-1' | ||
}), | ||
new WinstonCloudWatch({ | ||
name: 'second-stream', | ||
logGroupName: 'testing', | ||
logStreamName: 'second', | ||
awsRegion: 'us-east-1' | ||
}) | ||
] | ||
}); | ||
winston.loggers.add('category1', { | ||
// note that this is the same property name | ||
// that we've added to winston.transports | ||
CloudWatch1: { | ||
logGroupName: 'testing', | ||
logStreamName: 'first' | ||
} | ||
// both logs will be logged to both streams | ||
logger.error('something') | ||
logger.error('happened') | ||
const singleLogger = winston.createLogger({ | ||
transports: [ | ||
new WinstonCloudWatch({ | ||
name: 'first-stream', | ||
logGroupName: 'testing', | ||
logStreamName: 'first', | ||
awsRegion: 'us-east-1' | ||
}) | ||
] | ||
}); | ||
winston.loggers.add('category2', { | ||
// note that this is the same property name | ||
// that we've added to winston.transports | ||
CloudWatch2: { | ||
logGroupName: 'testing', | ||
logStreamName: 'second' | ||
} | ||
}); | ||
winston.loggers.get('category1').error('1'); | ||
winston.loggers.get('category2').error('2'); | ||
singleLogger.error('only on the first') |
@@ -7,8 +7,9 @@ var winston = require('winston'), | ||
// is CloudWatch | ||
winston.add(WinstonCloudWatch, { | ||
winston.add(new WinstonCloudWatch({ | ||
logGroupName: 'testing', | ||
logStreamName: 'first', | ||
retentionInDays: 14 | ||
}); | ||
logStreamName: 'another', | ||
awsRegion: 'us-east-1', | ||
retentionInDays: 14 | ||
})) | ||
winston.error('1'); |
@@ -7,3 +7,3 @@ var winston = require('winston'), | ||
// is CloudWatch | ||
winston.add(WinstonCloudWatch, { | ||
winston.add(new WinstonCloudWatch({ | ||
awsRegion: 'eu-west-1', | ||
@@ -15,4 +15,4 @@ awsOptions: { | ||
logStreamName: 'first' | ||
}); | ||
})); | ||
winston.error('1'); |
@@ -7,7 +7,8 @@ var winston = require('winston'), | ||
// is CloudWatch | ||
winston.add(WinstonCloudWatch, { | ||
winston.add(new WinstonCloudWatch({ | ||
logGroupName: 'testing', | ||
logStreamName: 'first' | ||
}); | ||
logStreamName: 'first', | ||
awsRegion: 'us-east-1' | ||
})); | ||
winston.error('1'); |
29
index.js
@@ -7,3 +7,5 @@ 'use strict'; | ||
cloudWatchIntegration = require('./lib/cloudwatch-integration'), | ||
_ = require('lodash'), | ||
isEmpty = require('lodash.isempty'), | ||
assign = require('lodash.assign'), | ||
isError = require('lodash.iserror'), | ||
stringify = require('./lib/utils').stringify, | ||
@@ -25,5 +27,3 @@ debug = require('./lib/utils').debug; | ||
var messageFormatter = options.messageFormatter ? options.messageFormatter : function(log) { | ||
return _.isEmpty(log.meta) && !(log.meta instanceof Error) ? | ||
[ log.level, log.msg ].join(' - ') : | ||
[ log.level, log.msg, stringify(log.meta) ].join(' - '); | ||
return [ log.level, log.message ].join(' - ') | ||
}; | ||
@@ -55,4 +55,4 @@ this.formatMessage = options.jsonMessage ? stringify : messageFormatter; | ||
if(options.awsOptions){ | ||
config = _.assign(config, options.awsOptions); | ||
if (options.awsOptions) { | ||
config = assign(config, options.awsOptions); | ||
} | ||
@@ -67,11 +67,10 @@ | ||
WinstonCloudWatch.prototype.log = function(level, msg, meta, callback) { | ||
debug('log (called by winston)', level, msg, meta); | ||
WinstonCloudWatch.prototype.log = function (info, callback) { | ||
debug('log (called by winston)', info); | ||
var log = { level: level, msg: msg, meta: meta }; | ||
if (!_.isEmpty(msg)) { | ||
this.add(log); | ||
if (!isEmpty(info.message) || isError(info.message)) { | ||
this.add(info); | ||
} | ||
if (!/^uncaughtException: /.test(msg)) { | ||
if (!/^uncaughtException: /.test(info.message)) { | ||
// do not wait, just return right away | ||
@@ -81,2 +80,4 @@ return callback(null, true); | ||
debug('message not empty, proceeding') | ||
// clear interval and send logs immediately | ||
@@ -94,3 +95,3 @@ // as Winston is about to end the process | ||
if (!_.isEmpty(log.msg)) { | ||
if (!isEmpty(log.message) || isError(log.message)) { | ||
self.logEvents.push({ | ||
@@ -122,3 +123,3 @@ message: self.formatMessage(log), | ||
if (_.isEmpty(this.logEvents)) { | ||
if (isEmpty(this.logEvents)) { | ||
return callback(); | ||
@@ -125,0 +126,0 @@ } |
@@ -7,3 +7,3 @@ var LIMITS = { | ||
var _ = require('lodash'), | ||
var find = require('lodash.find'), | ||
async = require('async'), | ||
@@ -77,2 +77,3 @@ stringify = require('./utils').stringify, | ||
aws.putLogEvents(payload, function(err, data) { | ||
debug('sent to aws, err: ', err, ' data: ', data) | ||
if (err) { | ||
@@ -195,3 +196,3 @@ // InvalidSequenceToken means we need to do a describe to get another token | ||
var stream = _.find(data.logStreams, function(stream) { | ||
var stream = find(data.logStreams, function(stream) { | ||
return stream.logStreamName === streamName; | ||
@@ -198,0 +199,0 @@ }); |
{ | ||
"name": "winston-cloudwatch", | ||
"version": "1.13.1", | ||
"version": "2.0.0", | ||
"description": "Send logs to Amazon Cloudwatch using Winston.", | ||
@@ -15,4 +15,4 @@ "keywords": [ | ||
"test": "make test", | ||
"coveralls": "./node_modules/.bin/coveralls <./coverage/lcov.info", | ||
"update-dependencies": "./node_modules/.bin/npm-check-updates -ua && npm install" | ||
"coveralls": "coveralls < ./coverage/lcov.info", | ||
"update-dependencies": "npm-check-updates -ua && npm install" | ||
}, | ||
@@ -24,23 +24,26 @@ "repository": "https://github.com/lazywithclass/winston-cloudwatch", | ||
"peerDependencies": { | ||
"winston": "^2.1.1" | ||
"winston": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"async": "^2.1.5", | ||
"aws-sdk": "^2.29.0", | ||
"chalk": "^1.1.3", | ||
"lodash": "^4.17.4", | ||
"proxy-agent": "^2.0.0" | ||
"async": "^2.6.1", | ||
"aws-sdk": "^2.259.1", | ||
"chalk": "^2.4.1", | ||
"lodash.assign": "^4.2.0", | ||
"lodash.find": "^4.6.0", | ||
"lodash.isempty": "^4.4.0", | ||
"lodash.iserror": "^3.1.1", | ||
"proxy-agent": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "7.0.8", | ||
"@types/winston": "2.2.0", | ||
"clarify": "^2.0.0", | ||
"coveralls": "^2.12.0", | ||
"@types/node": "10.3.4", | ||
"@types/winston": "2.3.9", | ||
"clarify": "^2.1.0", | ||
"coveralls": "^3.0.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
"mockery": "^2.0.0", | ||
"npm-check-updates": "^2.10.3", | ||
"should": "^11.2.1", | ||
"sinon": "^2.1.0" | ||
"mocha": "^5.2.0", | ||
"mockery": "^2.1.0", | ||
"npm-check-updates": "^2.14.2", | ||
"should": "^13.2.1", | ||
"sinon": "^6.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# winston-cloudwatch [v1.13.1](https://github.com/lazywithclass/winston-cloudwatch/blob/master/CHANGELOG.md#1131) | ||
# winston-cloudwatch [v2.0.0](https://github.com/lazywithclass/winston-cloudwatch/blob/master/CHANGELOG.md#200) | ||
@@ -3,0 +3,0 @@ [](https://travis-ci.org/lazywithclass/winston-cloudwatch) [](https://coveralls.io/github/lazywithclass/winston-cloudwatch?branch=master) [](https://david-dm.org/lazywithclass/winston-cloudwatch) [](https://david-dm.org/lazywithclass/winston-cloudwatch#info=devDependencies) [](https://david-dm.org/lazywithclass/winston-cloudwatch#info=peerDependencies) |
@@ -34,3 +34,6 @@ describe('index', function() { | ||
mockery.registerAllowable('util'); | ||
mockery.registerAllowable('lodash'); | ||
mockery.registerAllowable('lodash.find'); | ||
mockery.registerAllowable('lodash.assign'); | ||
mockery.registerAllowable('lodash.isempty'); | ||
mockery.registerAllowable('lodash.iserror'); | ||
mockery.registerAllowable('./lib/utils'); | ||
@@ -95,3 +98,3 @@ | ||
transport = new WinstonCloudWatch({}); | ||
transport.log('level', null, {key: 'value'}, function() { | ||
transport.log({ level: 'level' }, function() { | ||
clock.tick(2000); | ||
@@ -109,3 +112,3 @@ done(); | ||
transport = new WinstonCloudWatch({}); | ||
transport.log('level', 'uncaughtException: ', {}, function() { | ||
transport.log({ message: 'uncaughtException: ' }, function() { | ||
clock.tick(2000); | ||
@@ -128,6 +131,7 @@ should.not.exist(transport.intervalId); | ||
transport = new WinstonCloudWatch(options); | ||
transport.log('level', 'message', {key: 'value'}, function() { | ||
clock.tick(2000); | ||
done(); | ||
}); | ||
transport.log({ level: 'level', message: 'message', something: 'else' }, | ||
function() { | ||
clock.tick(2000); | ||
done(); | ||
}); | ||
}); | ||
@@ -139,4 +143,4 @@ | ||
jsonMessage.level.should.equal('level'); | ||
jsonMessage.msg.should.equal('message'); | ||
jsonMessage.meta.key.should.equal('value'); | ||
jsonMessage.message.should.equal('message'); | ||
jsonMessage.something.should.equal('else'); | ||
}); | ||
@@ -150,35 +154,12 @@ }); | ||
describe('using the default formatter', function() { | ||
var options = {}; | ||
describe('with metadata', function() { | ||
var meta = {key: 'value'}; | ||
before(function(done) { | ||
transport = new WinstonCloudWatch(options); | ||
transport.log('level', 'message', meta, done); | ||
clock.tick(2000); | ||
}); | ||
it('logs text', function() { | ||
var message = stubbedCloudwatchIntegration.lastLoggedEvents[0].message; | ||
message.should.equal('level - message - {\n "key": "value"\n}'); | ||
}); | ||
before(function(done) { | ||
transport = new WinstonCloudWatch(options); | ||
transport.log({ level: 'level', message: 'message' }, done); | ||
clock.tick(2000); | ||
}); | ||
describe('without metadata', function() { | ||
var meta = {}; | ||
before(function(done) { | ||
transport = new WinstonCloudWatch(options); | ||
transport.log('level', 'message', {}, done); | ||
clock.tick(2000); | ||
}); | ||
it('logs text', function() { | ||
var message = stubbedCloudwatchIntegration.lastLoggedEvents[0].message; | ||
message.should.equal('level - message'); | ||
}); | ||
it('logs text', function() { | ||
var message = stubbedCloudwatchIntegration.lastLoggedEvents[0].message; | ||
message.should.equal('level - message'); | ||
}); | ||
@@ -191,3 +172,3 @@ }); | ||
messageFormatter: function(log) { | ||
return 'custom formatted log message'; | ||
return log.level + ' ' + log.message + ' ' + log.something; | ||
} | ||
@@ -198,3 +179,3 @@ }; | ||
transport = new WinstonCloudWatch(options); | ||
transport.log('level', 'message', {key: 'value'}, done); | ||
transport.log({ level: 'level', message: 'message', something: 'else' }, done); | ||
clock.tick(2000); | ||
@@ -205,3 +186,3 @@ }); | ||
var message = stubbedCloudwatchIntegration.lastLoggedEvents[0].message; | ||
message.should.equal('custom formatted log message'); | ||
message.should.equal('level message else'); | ||
}); | ||
@@ -211,2 +192,17 @@ }); | ||
describe('info object and a callback as arguments', function() { | ||
before(function(done) { | ||
transport = new WinstonCloudWatch({}); | ||
transport.log({ level: 'level', message: 'message' }, function() { | ||
clock.tick(2000); | ||
done(); | ||
}); | ||
}); | ||
it('logs text', function() { | ||
var message = stubbedCloudwatchIntegration.lastLoggedEvents[0].message; | ||
message.should.equal('level - message'); | ||
}); | ||
}); | ||
describe('handles error', function() { | ||
@@ -232,3 +228,3 @@ | ||
}); | ||
transport.log('level', 'message', { answer: 42 }, sinon.stub()); | ||
transport.log({ level: 'level', message: 'message' }, sinon.stub()); | ||
clock.tick(2000); | ||
@@ -240,3 +236,3 @@ errorHandlerSpy.args[0][0].should.equal('ERROR'); | ||
var transport = new WinstonCloudWatch({}); | ||
transport.log('level', 'message', { answer: 42 }, sinon.stub()); | ||
transport.log({ level: 'level', message: 'message' }, sinon.stub()); | ||
clock.tick(2000); | ||
@@ -243,0 +239,0 @@ console.error.args[0][0].should.equal('ERROR'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
94379
73.48%24
9.09%1165
2.19%9
50%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated