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

support a context prop on the logger #345

Open
1 task
smeijer opened this issue Feb 3, 2025 · 0 comments
Open
1 task

support a context prop on the logger #345

smeijer opened this issue Feb 3, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@smeijer
Copy link

smeijer commented Feb 3, 2025

Describe the feature

It would be great to have a context prop on the instance, which accepts a Record<string, unknown>, which is then appended to the args argument (or the logObject) of any message logged.

This way it would be trivial to bind a logger to an http request, and add a trace-id to every logged message, or details about the authenticated user.

So basically;

const consola = createConsola({
  defaults: {
    context: { userId: 1 },
  }
});

consola.info('http request', { path: '/dashboard' })
  //    logObject: { args: ['http request', { path: '/dashboard' }, { userId: 1 }] }
  // or logObject: { args: ['http request', { path: '/dashboard' }], context: { userId: 1 } }

Additional information

  • Would you be willing to help implement this feature?
@smeijer smeijer added the enhancement New feature or request label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant