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 custom log payload support to logFormatter #4619

Merged
merged 5 commits into from
Mar 2, 2022

Conversation

dthyresson
Copy link
Contributor

Fixes #4154

As part of making dev logging less verbose, only certain objects were being logged: queries, timing, etc.

But, sometimes one wants to log ad-hoc custom payloads when debugging, but currently one has to use:

logger.debug({ query: { my_custom: value } }), 'Custom debug logging')

This PR adds the custom option:

logger.debug({ custom: { my_custom: value } }), 'Custom debug logging')

which will format the message text or object in a readable way with a label and emoji.

describe('Custom log data', () => {
    test('Should include the custom log attribute text', () => {
      expect(
        logFormatter({
          level: 10,
          custom: 'I should see this custom message text',
        })
      ).toMatch('I should see this')
    })

    test('Should include the custom log attribute info a custom emoji and label', () => {
      expect(
        logFormatter({
          level: 10,
          custom: 'I should see this custom emoji and label',
        })
      ).toMatch('🗒 Custom')
    })

    test('Should include the custom log attribute info with nested text message', () => {
      expect(
        logFormatter({
          level: 10,
          custom: {
            msg: 'I should see this custom message in the log',
          },
        })
      ).toMatch('I should see this custom message in the log')
    })
  })

  test('Should include the custom log attribute info with a number attribute', () => {
    expect(
      logFormatter({
        level: 10,
        custom: {
          msg: 'I should see this custom message and number in the log',
          number: 100,
        },
      })
    ).toMatch('100')
  })

  test('Should include the custom log attribute info with a nested object attribute', () => {
    expect(
      logFormatter({
        level: 10,
        custom: {
          msg: 'I should see this custom object in the log',
          obj: { foo: 'bar' },
        },
      })
    ).toMatch('"foo": "bar"')
  })

  test('Should include the custom log attribute info with a nested object attribute', () => {
    expect(
      logFormatter({
        level: 10,
        custom: {
          msg: 'I should see this custom object in the log',
          obj: { foo: 'bar' },
        },
      })
    ).toMatch('"foo": "bar"')
  })
})

Copy link
Collaborator

@simoncrypta simoncrypta left a comment

Choose a reason for hiding this comment

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

Everything works well, and I like the format and idea! 🗒

But just a little detail, I think you put one round brackets too many in your example.
logger.debug({ custom: { my_custom: value } } ), 'Custom debug logging')
logger.debug({ custom: { my_custom: value } }, 'Custom debug logging')
But when I removed it, it works as expect 👍

@dthyresson
Copy link
Contributor Author

Everything works well, and I like the format and idea! 🗒

But just a little detail, I think you put one round brackets too many in your example. logger.debug({ custom: { my_custom: value } } ), 'Custom debug logging') logger.debug({ custom: { my_custom: value } }, 'Custom debug logging') But when I removed it, it works as expect 👍

Yup, I did. Bad copy and paste.

Thanks!

@dthyresson dthyresson enabled auto-merge (squash) March 2, 2022 15:22
@dthyresson dthyresson merged commit 2fb0877 into redwoodjs:main Mar 2, 2022
@jtoar jtoar added this to the next-release milestone Mar 2, 2022
dac09 added a commit that referenced this pull request Mar 3, 2022
…rojects-to-yarn-3

* 'main' of github.com:redwoodjs/redwood: (29 commits)
  Update dependency eslint-config-prettier to v8.5.0 (#4631)
  Update dependency msw to v0.38.2 (#4630)
  Update dependency @clerk/types to v1.27.0 (#4628)
  Update dependency @clerk/clerk-js to v2.16.0 (#4627)
  Update dependency @types/react-dom to v17.0.13 (#4629)
  Update dependency @types/testing-library__jest-dom to v5.14.3 (#4624)
  Update dependency @types/aws-lambda to v8.10.93 (#4620)
  Webhook verifiers: Make them all support timestamp diff check (#4608)
  Add custom log payload support to logFormatter (#4619)
  Update dependency @types/react-dom to v17.0.12 (#4621)
  part II of #4623 (#4626)
  Update dependency systeminformation to v5.11.6 (#4611)
  Update dependency @clerk/clerk-js to v2.15.0 (#4606)
  remove Redwood extension from vscode rec (#4613)
  (fixture chore) pin fixture autoprefixer 9.8.8 (#4623)
  update yarn.lock
  v0.47.1
  update yarn.lock
  fixi(prisma): Set default cwd for runCommand task to base (#4604)
  Update actions/checkout action to v3 (#4610)
  ...
dac09 added a commit that referenced this pull request Mar 3, 2022
…ors-db-auth

* 'main' of github.com:redwoodjs/redwood:
  [WIP] Enable yarn 3 for Redwood projects (#4444)
  Update dependency eslint-config-prettier to v8.5.0 (#4631)
  Update dependency msw to v0.38.2 (#4630)
  Update dependency @clerk/types to v1.27.0 (#4628)
  Update dependency @clerk/clerk-js to v2.16.0 (#4627)
  Update dependency @types/react-dom to v17.0.13 (#4629)
  Update dependency @types/testing-library__jest-dom to v5.14.3 (#4624)
  Update dependency @types/aws-lambda to v8.10.93 (#4620)
  Webhook verifiers: Make them all support timestamp diff check (#4608)
  Add custom log payload support to logFormatter (#4619)
@thedavidprice thedavidprice modified the milestones: next-release, v0.48.0 Mar 4, 2022
@Tobbe Tobbe mentioned this pull request Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:chore This PR is a chore (means nothing for users)
Projects
No open projects
Status: Archived
Development

Successfully merging this pull request may close these issues.

Redwood Logger - Add an option to log object payloads other than standard allowed objects
4 participants