-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Bunyan and Loggly updates #2425
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9442f4a
switch to official Loggly lib for Node and write new Bunyan connector…
jshimko 2b3408d
update bunyan to 2.0.0
jshimko 6987131
fix Logger imports
jshimko 59fc246
Merge branch 'development' into bunyan-and-loggly-updates
79e93ec
add REACTION_LOG_FORMAT config option
jshimko 17e67e1
add extra comments about log formatting options
jshimko 66de9f2
Merge branch 'development' into bunyan-and-loggly-updates
jshimko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Logger } from "./main"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import loggly from "node-loggly-bulk"; | ||
|
||
class Bunyan2Loggly { | ||
constructor(logglyConfig, bufferLength = 1, bufferTimeout, callback) { | ||
if (!logglyConfig || !logglyConfig.token || !logglyConfig.subdomain) { | ||
throw new Error("bunyan-loggly requires a config object with token and subdomain"); | ||
} | ||
|
||
logglyConfig.json = true; | ||
|
||
this.logglyClient = loggly.createClient(logglyConfig); | ||
|
||
this._buffer = []; | ||
this.bufferLength = bufferLength; | ||
this.bufferTimeout = bufferTimeout; | ||
this.callback = callback || function () {}; | ||
} | ||
|
||
write(data) { | ||
if (typeof data !== "object") { | ||
throw new Error("bunyan-loggly requires a raw stream. Please define the type as raw when setting up the bunyan stream."); | ||
} | ||
|
||
// loggly prefers timestamp over time | ||
if (data.time) { | ||
data.timestamp = data.time; | ||
delete data.time; | ||
} | ||
|
||
this._buffer.push(data); | ||
|
||
this._checkBuffer(); | ||
} | ||
|
||
_processBuffer() { | ||
clearTimeout(this._timeoutId); | ||
|
||
let content = this._buffer.slice(); | ||
|
||
this._buffer = []; | ||
|
||
if (content.length === 1) { | ||
content = content[0]; | ||
} | ||
|
||
this.logglyClient.log(content, (error, result) => { | ||
this.callback(error, result, content); | ||
}); | ||
} | ||
|
||
_checkBuffer() { | ||
if (!this._buffer.length) { | ||
return; | ||
} | ||
|
||
if (this._buffer.length >= this.bufferLength) { | ||
return this._processBuffer(); | ||
} | ||
|
||
if (this.bufferTimeout) { | ||
clearTimeout(this._timeoutId); | ||
this._timeoutId = setTimeout(() => { this._processBuffer(); }, this.bufferTimeout); | ||
} | ||
} | ||
} | ||
|
||
export default Bunyan2Loggly; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we not going to have a "trace" dump then, or was this just an unlikely use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, my thinking here was that the default stdout output stream (the console) is intended entirely for human consumption, so readability should be the main focus of the stdout configuration. Also, there isn't really anything that an unformatted output gives you that's unique or useful. The only things the formatter strips out is the hostname and pid (process ID). Any other objects (errors, data, etc.) passed to the logger calls for debugging are still included in the formatted log output. The main advantage being that they're much easier to read when formatted like that. So in short, all of the same data gets shown, it's just easier to parse visually when it's run through the formatter.
However, in case someone really wants to have that raw JSON output, I added a new env var (
REACTION_LOG_FORMAT
) which you can use to set the formatter. So...outputs this...
And technically you could set that to anything
bunyan-format
supports. Which is...short|long|simple|json|bunyan
(default: short)Sort of relevant... there's not a single instance of
Logger.trace()
in the whole app, so this shouldn't have any effect on anyone's current experience.