Closed Enado95 closed 5 years ago
I'm trying to use it like so as well:
'Test' + ('{{res.statusCode}}'== '401' ? ' ' : ' Username: {{req.user.preferred_username}}' )
Are you talking about the \u001b[33m
style strings? Those are color codes for the terminal. Do you have colorize: true
set in your logger options? The color codes should go away if the colorize
option is falsy.
I do have it set to true. Will try again later on and advise of results.
Okay so setting the colorize to false gives me back the statusCode but my conditional statement wont work:
msg: 'Test' + ('{{res.statusCode}}'== '401' ? ' ' : ' Username: {{req.user.preferred_username}}' )
So i want to get an empty string if the statusCode is 401 otherwise I'll print the username from the user object that I've populated. Can this be done ?
There's probably a way to make what you want work with a mustache template string, but it might get pretty difficult to understand since I think you'd need your ternary to be inside the {{}}
. You might want to switch to using a function for msg
instead (supported as of v2.6.0). Something like this would probably do what you want?
msg: (req, res) => 'Test' + (res.statusCode == 401 ? ' ' : ` Username: ${req.user.perferred_username}`)
Thanks a million! It works just as expected.
When I use the res.statusCode in the msg property, it returns a not so favorable response
code:
msg: 'Statuscode {{res.statusCode}}'
result of res.statusCode:
"message": "\u001b[33m401\u001b[39m"
Is there anyway to go around this?