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

Access log level in logMethod hook #909

Closed
gzaripov opened this issue Sep 14, 2020 · 9 comments
Closed

Access log level in logMethod hook #909

gzaripov opened this issue Sep 14, 2020 · 9 comments

Comments

@gzaripov
Copy link

I want to collect logs number statistics and I want also to categorize them by levels.
For now I cant get level from logMethod hook, so I cant collect info about method types, lets add it to logMethod hook:

const hooks = {
  logMethod (inputArgs, method, { level }) {
    metrics.registerEvent(`log_${level}`);
    return method.apply(this, inputArgs)
  }
}
@mcollina
Copy link
Member

It is not needed as you can get it with https://github.com/pinojs/pino/blob/83d80f63888aa0b68479d460706644c58257131c/docs/api.md#levels.

logger.levels.values[method]

@gzaripov
Copy link
Author

gzaripov commented Sep 14, 2020

@mcollina could you provide exact solution? I try to call this.levels.values[method] inside function and I get undefined.
Here is reproduction https://codesandbox.io/s/funny-shannon-e8elg?file=/src/start.js

To see logs just make some change, i.e. add enter and press cmd+s, it will re-run server and logs come up in terminal window

@mcollina mcollina reopened this Sep 14, 2020
@mcollina
Copy link
Member

Actually I was wrong, that's not feasible right now.

What's your use case exactly?

@jsumners
Copy link
Member

Support would need to be added at:

pino/lib/tools.js

Lines 30 to 35 in 95856d1

function genLog (level, hook) {
if (!hook) return LOG
return function hookWrappedLog (...args) {
hook.call(this, args, LOG)
}

@gzaripov
Copy link
Author

What's your use case exactly?

I want to provide more info about what kind of logs we are logging in node server. It will help us to track new problems when error logs count was increased. For now I can track only total amount of logs.

@gzaripov
Copy link
Author

I suggest this solution:

function genLog (level, hook) {
  if (!hook) return LOG

  return function hookWrappedLog (...args) {
    hook.call(this, args, LOG, { level })
  }

@mcollina
Copy link
Member

Please avoid creating a new object, e.g. level not { level }.

@mojavelinux
Copy link
Contributor

FYI, this appears to have been resolved but never closed.

@github-actions
Copy link

github-actions bot commented Feb 4, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants