You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I edit the source for name and remove the default padding, things behave.
As an alternative solution I looked through the docs in regards to dynamicFormats and staticFormats and it's unclear how to use those formats once created.
I guess the issue is that you want to set padding to zero. I suspect it works with non-zero positive numbers right?
I am open to a PR that changes the number check so it accepts zero.
About formats.... You should be able to create a custom static format that uses the logger.name. But I think fixing the number check would be better for this specific scenario. Setting padding to zero seems like a very legit scenario.
If you want to play with making your own static/dynamic formats I'd be happy to help you clear up any confusion. I admit the docs probably need some more work so getting some feedback on what is unclear would be helpful. Basically the formatter function that contains the number check is just a helper function to make it a bit easier to create formatters that support colors and padding out of the box. You can also bypass that function.
To make a format available, you add a mod with a key formats like is done here.
For example, try something like this:
varulog=require('ulog')ulog.use({formats: {stat: (ctx,rec)=>()=>{// rec.message is undefined in static formats, // but we can use most other props from `rec`returnrec.name// no padding},dyn: (ctx)=>(rec)=>{// since this is a dynamic format, rec.message will // contain the log message argumentsreturnrec.name// no padding}}})
After adding the mod like this, you should be able to use the new formats stat and dyn in your format string.
E.g.
LOG_FORMAT=lvl stat
This should use the static format and hence not break line numbers.
Or
LOG_FORMAT=lvl dyn message
This will use the dynamic formats dyn and message and so unfortunately break line numbers.
Please check the docs for custom formats and let me know if / how we should change them to make it more clear.
The above is a snippet from a logger function that's shared by Client and Server, and FOR_CLIENT_BUNDLE is only defined when Client bundles are generated via Webpack.
I also agree that it'd be better to be fixed (hence the open issue), unfortunately I too am busy and don't know if/when I'll have the time to dig into your repo and it's tests to open a PR.
About your update: Using code like that is not recommended. You bypass everything that way and won't be able to change the formatting using the config mechanisms described in the docs
I know making PRs sucks, but it looks like all you need to do is:
Fork this repo
Clone your fork
npm install
Add a test that sets a format with padding set to 0
Activity
Download commentedon Jul 24, 2021
Sorry for letting you dangle. Been very busy...
I guess the issue is that you want to set padding to zero. I suspect it works with non-zero positive numbers right?
I am open to a PR that changes the number check so it accepts zero.
About formats.... You should be able to create a custom static format that uses the logger.name. But I think fixing the number check would be better for this specific scenario. Setting padding to zero seems like a very legit scenario.
If you want to play with making your own static/dynamic formats I'd be happy to help you clear up any confusion. I admit the docs probably need some more work so getting some feedback on what is unclear would be helpful. Basically the
formatterfunction that contains the number check is just a helper function to make it a bit easier to create formatters that support colors and padding out of the box. You can also bypass that function.To make a format available, you add a mod with a key
formatslike is done here.For example, try something like this:
After adding the mod like this, you should be able to use the new formats
statanddynin your format string.E.g.
LOG_FORMAT=lvl statThis should use the static format and hence not break line numbers.
Or
LOG_FORMAT=lvl dyn messageThis will use the dynamic formats
dynandmessageand so unfortunately break line numbers.Please check the docs for custom formats and let me know if / how we should change them to make it more clear.
the0neWhoKnocks commentedon Jul 31, 2021
Correct, I want to set the padding to zero, and yes it works for non-zero values.
After not hearing anything on this ticket for a while I added this.
The above is a snippet from a
loggerfunction that's shared by Client and Server, andFOR_CLIENT_BUNDLEis only defined when Client bundles are generated via Webpack.I also agree that it'd be better to be fixed (hence the open issue), unfortunately I too am busy and don't know if/when I'll have the time to dig into your repo and it's tests to open a PR.
Update
Turns out I can also just have
Download commentedon Aug 2, 2021
About your update: Using code like that is not recommended. You bypass everything that way and won't be able to change the formatting using the config mechanisms described in the docs
I know making PRs sucks, but it looks like all you need to do is:
If you keep it simple I will merge ASAP