winston-cloudwatch
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -0,1 +1,5 @@ | ||
### 0.8.0 | ||
Group or stream are created if they are not found | ||
### 0.7.0 | ||
@@ -2,0 +6,0 @@ |
@@ -7,2 +7,3 @@ var AWS = require('aws-sdk'), | ||
logStreamName = '', | ||
messageAsJSON, | ||
intervalId; | ||
@@ -27,5 +28,5 @@ | ||
message: messageAsJSON ? JSON.stringify(log, null, ' ') : [log.level, log.msg, JSON.stringify(log.meta, null, ' ')].join(' - '), | ||
timestamp: new Date().getTime() | ||
timestamp: new Date().getTime() | ||
}); | ||
var lastFree = new Date().getTime(); | ||
@@ -38,7 +39,7 @@ function upload() { | ||
} | ||
if (logEvents.length <= 0) { | ||
return; | ||
} | ||
var payload = { | ||
@@ -56,3 +57,3 @@ logGroupName: logGroupName, | ||
}); | ||
} | ||
} | ||
} | ||
@@ -71,3 +72,9 @@ if (!intervalId) { | ||
cloudwatchlogs.describeLogStreams(params, function(err, data) { | ||
if (err) return cb(err); | ||
if (err) { | ||
if(err.code === 'ResourceNotFoundException'){ | ||
return createLogGroup(logGroupName, cb); | ||
} | ||
return cb(err); | ||
} | ||
var matches = _.find(data.logStreams, function(logStream) { | ||
@@ -83,3 +90,3 @@ return (logStream.logStreamName === logStreamName); | ||
} | ||
}) | ||
}); | ||
} | ||
@@ -92,2 +99,5 @@ next(); | ||
if (err) { | ||
if(err.message === 'Stream not found'){ | ||
return createLogStream(logGroupName, logStreamName, cb); | ||
} | ||
return cb(err); | ||
@@ -98,1 +108,20 @@ } | ||
} | ||
function createLogStream(logGroupName, logStreamName, cb){ | ||
cloudwatchlogs.createLogStream({ | ||
logGroupName: logGroupName, | ||
logStreamName: logStreamName | ||
}, function(err, data){ | ||
if(err) cb(err); | ||
else token(cb); | ||
}); | ||
} | ||
function createLogGroup(logGroupName, cb){ | ||
cloudwatchlogs.createLogGroup({ | ||
logGroupName: logGroupName | ||
}, function(err, data){ | ||
if(err) cb(err); | ||
else findLogStream(logGroupName, logStreamName, cb); | ||
}); | ||
} |
{ | ||
"name": "winston-cloudwatch", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "Send logs to Amazon Cloudwatch using Winston.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -23,2 +23,4 @@ # winston-cloudwatch <br /> | ||
If either the group or the stream do not exist they will be created for you. | ||
## Usage | ||
@@ -25,0 +27,0 @@ |
11437
149
72