Don't modify arguments passed to logging methods
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
-
winston@3
-
node -v
outputs: v11.4.0- Operating System? (Linux)
- Language? (ES6/7)
What is the problem?
Winston modifies objects passed to it!
I have a webservice with error handler:
handleError(err, req, res, next) {
winston.warn(err)
res.status(err.status || err.statusCode || 500).json(err)
}
I expect, say, a 404 response with body {"message":"Not Found"}
, but with the winston.warn
call included, it becomes {"message":"Not Found","level":"warn"}
. Of course, it’s worse after going through formatters—I get tabs, ANSI color codes, etc.—but out of the box I still get the level
property.
What do you expect to happen instead?
No mutation
Other information
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:8 (3 by maintainers)
Top Results From Across the Web
c# - How to disable evaluation of parameters in a method
When I disable logger in settings (so the _isActive field in Logger class is false), then nothing is saved to database. But all...
Read more >java - Is it still a good practice to log parameters and returns?
I am currently setting up the logging of the application and I stumbled upong this url and found it helpful. Although it is...
Read more >Python logging: do's and don'ts - palkeo
It will work fine. But it's bad. Don't do it. Instead, all the logging methods accept a string and arbitrary number of parameters....
Read more >A better way to logging in Python | F5 - Squashing Bugs
We can do this by just iterating over args and kwargs and joining them to form string message to log.
Read more >logging — Logging facility for Python — Python 3.11.1 ...
If this attribute evaluates to true, events logged to this logger will be passed to the handlers of higher level (ancestor) loggers, in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The log utility we use can’t have side effects. This is a deal-breaker for us, unfortunately.
This is by design. The README for
info
clearly states that the objects are mutable. In this particular case, you could avoid the mutability if you wished, but opting not to use the convenience method.warn
. Instead:@sparkida unfortunately there is no easy way to handle all permutations of possible inputs that folks which to provide. In particular the desire of most developers includes:
logger.log('info', 'Interpolate %s [%j]', 'please', { myData: 'stuff' })
)Error
instances having non-enumerable properties.… and many others. In general from a historical perspective,
winston@1
, andwinston@2
did clone each object that was passed to it. This led to an significantly lower performance – which as a project we sought to fix inwinston@3
.There are trade-offs for performance vs. features. We opt for performance whenever possible.