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

customLevels brake logging with transports #1677

Closed
Sveeborg opened this issue Mar 23, 2023 · 5 comments · Fixed by #1760
Closed

customLevels brake logging with transports #1677

Sveeborg opened this issue Mar 23, 2023 · 5 comments · Fixed by #1760

Comments

@Sveeborg
Copy link

Hello!

pino 8.11.0

When customLevels is defined and transport level is equal to custom level, logging does not work, but no exceptions occur.

This works fine:

const transport = pino.transport({
  targets: [
    {
      level: 'info', // standard level
      target: 'pino-pretty',
      options: {
        translateTime: "yyyy-mm-dd'T'HH:MM:ss'Z'",
        ignore: 'pid,hostname',
        customLevels: 'serious:35',
        customColors: 'serious:green',
        useOnlyCustomProps: false,
      },
    },
  ],
})

const LOG = pino(
  {
    level: 'trace',
    customLevels: {
      serious: 35,
    },
  },
  transport
)

This does not work:

const transport = pino.transport({
  targets: [
    {
      level: 'serious', // custom level
      target: 'pino-pretty',
      options: {
        translateTime: "yyyy-mm-dd'T'HH:MM:ss'Z'",
        ignore: 'pid,hostname',
        customLevels: 'serious:35',
        customColors: 'serious:green',
        useOnlyCustomProps: false,
      },
    },
  ],
})

const LOG = pino(
  {
    level: 'trace',
    customLevels: {
      serious: 35,
    },
  },
  transport
)

Problem is not in pino-pretty. Another transports behave similarly.

If I add cusom level into pino levels.js, all works fine:

// pino/lib/levels.js
// ...
const levels = {
  trace: 10,
  debug: 20,
  info: 30,
  serious: 35,
  warn: 40,
  error: 50,
  fatal: 60
}
// ...
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@Sveeborg
Copy link
Author

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Ok, i will try.

@tzviki
Copy link
Contributor

tzviki commented Jul 30, 2023

This could be fixed by specifying all levels in the options for the transport. For example:

const transport = pino.transport({
    targets: [{
      level: 'info',
      target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
      options: { destination: dest1 }
    }, {
      level: 'foo',
      target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
      options: { destination: dest2 }
    }],
    levels: { trace: 10, debug: 20, info: 30, warn: 40, error: 50, fatal: 60, foo: 25 }
  })

I made a PR here to allow it to work without specifying default levels, but this can be ignored if this isn't expected behaviour.

@tzviki
Copy link
Contributor

tzviki commented Aug 30, 2023

I updated the pr that closes this issue. It probably has to manually be closed. Sorry didn't initially include it

@github-actions
Copy link

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 Sep 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants