Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined issue while logging from node-loggly-bulk library #11

Merged
merged 3 commits into from Jun 6, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -28,14 +28,20 @@ function stringify(msg) {
//
// function to truncate message over 1 MB
//
function truncateLargeMessage(message) {
function truncateLargeMessage(message) {
var maximumBytesAllowedToLoggly = EVENT_SIZE;
var bytesLengthOfLogMessage = Buffer.byteLength(message);
var bytesLengthOfLogMessage = Buffer.byteLength(message);
var isMessageTruncated = false;
if(bytesLengthOfLogMessage > maximumBytesAllowedToLoggly) {
message = message.slice(0, maximumBytesAllowedToLoggly);
isMessageTruncated = true;
}
return message;
return {
message: message,
isMessageTruncated: isMessageTruncated
};
}

//
// function createClient (options)
// Creates a new instance of a Loggly client.
@@ -105,7 +111,18 @@ util.inherits(Loggly, events.EventEmitter);
// - http://www.loggly.com/docs/api-sending-data/
//
Loggly.prototype.log = function (msg, tags, callback) {
msg.message = truncateLargeMessage(msg.message)
// typeof msg is string when we are using node-loggly-bulk to send logs.
// If we are sending logs using winston-loggly-bulk, msg is object.
// Check if 'msg' is an object, if yes then stringify it to truncate it over 1MB.
var truncatedMessageObject = null;
if(typeof(msg) === 'object'){
var stringifiedMessage = JSON.stringify(msg)
truncatedMessageObject = truncateLargeMessage(stringifiedMessage);
msg = truncatedMessageObject.isMessageTruncated ? truncatedMessageObject.message : msg;
}else if (typeof(msg) === 'string') {
truncatedMessageObject = truncateLargeMessage(msg);
msg = truncatedMessageObject.isMessageTruncated ? truncatedMessageObject.message : msg;
}
if (!callback && typeof tags === 'function') {
callback = tags;
tags = null;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.