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

Add logfmt support #2047

Merged
merged 39 commits into from
Aug 30, 2017
Merged

Add logfmt support #2047

merged 39 commits into from
Aug 30, 2017

Conversation

KingNoosh
Copy link
Member

@KingNoosh KingNoosh commented Aug 25, 2017

Changes proposed in this pull request:

  • Add support for the logfmt format (key=val)

Checklist:

  • docs updated
  • tests updated

@KingNoosh
Copy link
Member Author

The logfmt format is also supported and can be enabled by changing
LOGFMTDEFAULT to LOGFMTLOGFMT in the config/logformat 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"

Any objects you pass through will also be appeneded to the log line as
key=value and will look like this:

level=NOTICE connection_uuid=9FF7F70E-5D57-435A-AAD9-EA069B6159D9.1 source=core message=disconnect ip=127.0.0.1 rdns=Unknown helo=3h2dnz8a0if relay=N early=N esmtp=N tls=N pipe=N errors=0 txns=1 rcpts=1/0/0 msgs=1/0/0 bytes=222 lr="" time=0.052

You can find out more about logfmt here: https://brandur.org/logfmt

@haraka haraka deleted a comment from codecov bot Aug 25, 2017
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');
Copy link
Member

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.

Copy link
Member Author

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

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",
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Collaborator

@smfreegard smfreegard left a 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.

@haraka haraka deleted a comment from smfreegard Aug 28, 2017
@haraka haraka deleted a comment from smfreegard Aug 28, 2017
@haraka haraka deleted a comment from baudehlo Aug 28, 2017
@msimerson
Copy link
Member

I have removed the log.ini portions from this PR, having moved them over to #2054 where they have continued.

@haraka haraka deleted a comment from codecov bot Aug 28, 2017
@msimerson
Copy link
Member

@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 git merge.

@smfreegard
Copy link
Collaborator

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:

smf@i7desktop:~$ time node haraka_logger1.js 2>&1 > /dev/null

real	0m4.343s
user	0m4.148s
sys	0m0.244s

Here is the same but using logfmt.stringify:

smf@i7desktop:~$ time node haraka_logger2.js 2>&1 > /dev/null

real	0m11.633s
user	0m11.448s
sys	0m0.252s

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 logger.js. It should be lazy loaded if it's enabled and you should probably document the performance hit over standard logging as this seems pretty considerable to me.

For completeness I also changed the code to use es6 literals:

smf@i7desktop:~$ time node haraka_logger3.js 2>&1 > /dev/null

real	0m3.589s
user	0m3.472s
sys	0m0.168s

So that would be 17.36% faster

And I did the same by changing to the code to + ' ' + concatenate everything without using an Array:

smf@i7desktop:~$ time node haraka_logger4.js 2>&1 > /dev/null

real	0m5.060s
user	0m4.864s
sys	0m0.228s

Whist surprised me a bit as it's 16.51% slower than doing array.concat(' ' ).

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.

@haraka haraka deleted a comment from codecov bot Aug 29, 2017
@KingNoosh
Copy link
Member Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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"
Copy link
Collaborator

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 ?

Copy link
Member Author

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?

Copy link
Member Author

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: '-',
Copy link
Collaborator

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]({
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops - missed one.

@smfreegard smfreegard merged commit c17da20 into haraka:master Aug 30, 2017
@KingNoosh KingNoosh deleted the feature/logformat branch September 1, 2017 12:11
@haraka haraka deleted a comment from codecov bot Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants