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 some docs about how to use scope #51

Open
mattwynne opened this issue Nov 3, 2020 · 1 comment
Open

Add some docs about how to use scope #51

mattwynne opened this issue Nov 3, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@mattwynne
Copy link

Hey, thanks for this little gem of a library 👍 🎉

I was trying to figure out how to replace the default zoya scope in the log messages, and here's what I came up with:

const logger = zoya({
  fields: [scope({ scopes: ['main'] }), separator(), badge(), label(), separator(), message(), context()],
})

Is this the right way to do it? I figured this out by reading the tests (which were very easy to read 👍 ) but I'm not sure if I've missed something:

  • why is scopes an array? What happens if I define multiple scopes?
  • can I specify the scope when logging a message? If so, how?

I guess some more examples might be useful. The santa one is cute but not very illustrative :)

If you prefer to just explain to me here in the issue how to use it, I can send a PR with an update to the docs.

@WoLfulus
Copy link
Owner

WoLfulus commented Nov 30, 2020

Hey!

Glad you liked it, and sorry for just seeing this today.

why is scopes an array? What happens if I define multiple scopes?

The scopes are just a way to differentiate the log sources, I use it when outputting JSON to log aggregators that supports extraction/filters.

You can use transform to output scopes in a different format if you want (in text mode)

can I specify the scope when logging a message? If so, how?

Unfortunately there's no way to change the scope when writing individual messages, but you can use the enhance example to clone the same logger setup into different scopes and use those instead.

@WoLfulus WoLfulus added the enhancement New feature or request label Nov 30, 2020
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

2 participants