@google-cloud/logging-bunyan
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "@google-cloud/logging-bunyan", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Google Inc.", | ||
@@ -31,3 +31,4 @@ "description": "Stackdriver Logging stream for Bunyan", | ||
"dependencies": { | ||
"@google-cloud/logging": "^0.7.0" | ||
"@google-cloud/logging": "^0.8.1", | ||
"extend": "^3.0.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
@@ -23,3 +23,6 @@ /*! | ||
var extend = require('extend'); | ||
var logging = require('@google-cloud/logging'); | ||
var util = require('util'); | ||
var Writable = require('stream').Writable; | ||
@@ -95,4 +98,11 @@ /** | ||
this.log_ = logging(options).log(this.logName_); | ||
this.log_ = logging(options).log(this.logName_, { | ||
removeCircular: true | ||
}); | ||
Writable.call(this, { | ||
objectMode: true | ||
}); | ||
} | ||
util.inherits(LoggingBunyan, Writable); | ||
@@ -123,3 +133,3 @@ /** | ||
/** | ||
* Relay a log entry to the logging agent. This is normally called by bunyan. | ||
* Format a bunyan record into a Stackdriver log entry. | ||
* | ||
@@ -130,3 +140,3 @@ * @param {object} record - Bunyan log record. | ||
*/ | ||
LoggingBunyan.prototype.write = function(record) { | ||
LoggingBunyan.prototype.formatEntry_ = function(record) { | ||
if (typeof record === 'string') { | ||
@@ -138,4 +148,26 @@ throw new Error( | ||
var level = BUNYAN_TO_STACKDRIVER[record.level]; | ||
// Stackdriver Log Viewer picks up the summary line from the 'message' field | ||
// of the payload. Unless the user has provided a 'message' property also, | ||
// move the 'msg' to 'message'. | ||
if (!record.message) { | ||
// Clone the object before modifying it. | ||
record = extend({}, record); | ||
// If this is an error, report the full stack trace. This allows Stackdriver | ||
// Error Reporting to pick up errors automatically (for severity 'error' or | ||
// higher). In this case we leave the 'msg' property intact. | ||
// https://cloud.google.com/error-reporting/docs/formatting-error-messages | ||
// | ||
// TODO(ofrobots): when resource.type is 'global' we need to additionally | ||
// provide serviceContext.service as part of the entry for Error Reporting | ||
// to automatically pick up the error. | ||
if (record.err && record.err.stack) { | ||
record.message = record.err.stack; | ||
} else if (record.msg) { | ||
// Simply rename `msg` to `message`. | ||
record.message = record.msg; | ||
delete record.msg; | ||
} | ||
} | ||
var entryMetadata = { | ||
@@ -146,10 +178,22 @@ resource: this.resource_, | ||
var entry = this.log_.entry(entryMetadata, record); | ||
return this.log_.entry(entryMetadata, record); | ||
}; | ||
this.log_[level](entry, function() { | ||
// no-op to avoid a promise being returned. | ||
}); | ||
/** | ||
* Relay a log entry to the logging agent. This is called by bunyan through | ||
* Writable#write. | ||
* | ||
* @param {object} record - Bunyan log record. | ||
* | ||
* @private | ||
*/ | ||
LoggingBunyan.prototype._write = function(record, encoding, callback) { | ||
var entry = this.formatEntry_(record); | ||
var level = BUNYAN_TO_STACKDRIVER[record.level]; | ||
this.log_[level](entry, callback); | ||
}; | ||
// TODO(ofrobots): implement _writev as well. | ||
module.exports = LoggingBunyan; | ||
module.exports.BUNYAN_TO_STACKDRIVER = BUNYAN_TO_STACKDRIVER; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22725
175
2
+ Addedextend@^3.0.0
+ Added@google-cloud/common-grpc@0.2.1(transitive)
+ Added@google-cloud/logging@0.8.1(transitive)
+ Addedd64@1.0.0(transitive)
+ Addedeventid@0.1.2(transitive)
- Removed@google-cloud/common-grpc@0.1.6(transitive)
- Removed@google-cloud/logging@0.7.1(transitive)
- Removedis-circular@1.0.2(transitive)
Updated@google-cloud/logging@^0.8.1