-
-
Notifications
You must be signed in to change notification settings - Fork 661
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
Add logfmt support #2047
Add logfmt support #2047
Conversation
The logfmt format is also supported and can be enabled by changing
Any objects you pass through will also be appeneded to the log line as
You can find out more about logfmt here: https://brandur.org/logfmt |
b30696e
to
f8e0315
Compare
connection.js
Outdated
@@ -23,6 +22,7 @@ var trans = require('./transaction'); | |||
var plugins = require('./plugins'); | |||
var rfc1869 = require('./rfc1869'); | |||
var outbound = require('./outbound'); | |||
var ResultStore = require('haraka-results'); |
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.
Just curious, why move this down? The general format you'll find in most files is a section of node.js builtin modules, then a section of NPM modules, and finally a section of local (./) modules.
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.
It was a mistake, I based this off the older one and reverted a lot of stuff, this should've been one of them, fixing now
Signed-off-by: Anosh Malik <[email protected]>
package.json
Outdated
@@ -23,6 +23,7 @@ | |||
"iconv" : "~2.3.0", | |||
"ipaddr.js" : "~1.5.0", | |||
"js-yaml" : "~3.9.0", | |||
"logfmt" : "^1.2.0", |
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.
Shouldn't this be an optional dependency?
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.
Nope, this is being used for default too, line 275 of logger.js
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.
As per my comments.
I have removed the log.ini portions from this PR, having moved them over to #2054 where they have continued. |
@KingNoosh , are you familiar with the git witchcraft known as rebasing? If so, please do the needful. If not, catch me on IRC, or just use |
Ok - you don't appear to have benchmarked this like I suggested on IRC. I also didn't appreciate that you had made logfmt integral to logger. Adding new dependencies into core shouldn't be done without very good reason. Here is why: I've just done some really basic benchmarks which do a console.log of a single log line 1 million times. I picked the disconnect log line as it's the worst case as it puts everything inside an Array and then joins the array by ' ', so this is the worst example. It's also quite a long log line which was the other reason I picked it. This is the original disconnect log line with the original code:
Here is the same but using logfmt.stringify:
That's 167.86% slower.... So, there's no way I'm going to approve this pull request with logfmt being used by default in For completeness I also changed the code to use es6 literals:
So that would be 17.36% faster And I did the same by changing to the code to + ' ' + concatenate everything without using an Array:
Whist surprised me a bit as it's 16.51% slower than doing So es6 literals are the fastest way to handle this. However I suggest you simply revert the changes to all of the log lines as changing log lines to es6 literals should be done in a separate pull request. |
With the changes suggested from IRC, this should be ready to review again. |
docs/Logging.md
Outdated
the logger.js log\* method. objects-as-arguments are then sniffed | ||
to try to determine if they're a connection or plugin instance. | ||
<<<<<<< HEAD:docs/Logging_API.md |
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.
You've got a merge conflict marker here that you've forgotten to remove
docs/Logging.md
Outdated
|
||
You can find out more about logfmt here: [https://brandur.org/logfmt](https://brandur.org/logfmt) | ||
======= | ||
>>>>>>> upstream/master:docs/Logging.md |
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.
And another two here.
docs/Logging.md
Outdated
from `default` to `logfmt` in the `config/log.ini` file which will | ||
start logging in the following format below. | ||
|
||
level=PROTOCOL connection_uuid=9FF7F70E-5D57-435A-AAD9-EA069B6159D9.1 source=core message="S: 354 go ahead, make my day" |
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.
I thought connection_uuid
was changed to uuid
?
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.
It's still connection_uuid
, do you want me to rename to uuid
?
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.
nvm
logger.js
Outdated
var pluginstr = '[' + (plugin || 'core') + ']'; | ||
var logobj = { | ||
level, | ||
connection_uuid: '-', |
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.
Ok - it appears not. This isn't going to be a connection_uuid, it could be a transaction ID or an outbound recipient ID. So uuid
is far more appropriate (and terse).
'retval=' + constants.translate(retval), | ||
'msg="' + ((msg) ? msg : '') + '"', | ||
].join(' ')); | ||
object[log]({ |
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.
Can you align this block like it was before.
docs/Logging.md
Outdated
@@ -21,25 +21,25 @@ See also | |||
------------------ | |||
[https://github.com/haraka/Haraka/pull/119](https://github.com/haraka/Haraka/pull/119) | |||
|
|||
logline will always always be in the form: | |||
The logline by default will be in the form of: | |||
|
|||
[level] [connection uuid] [origin] message |
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.
Ooops - missed one.
Changes proposed in this pull request:
Checklist: