File logging reconfiguration issue (Error: write after end)
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
- [ X]
winston@3
-
- _
node -v
outputs:_v10.15.0 - _Operating System?_Windows 10
- _Language? JavaScript (pure Node)
What is the problem?
When logger is reconfigured, the open streams are destroyed and winston
tries to write to an already destroyed stream.
I created a really simple playground to replicate it (less than 10 lines of actual code): https://github.com/peterbakonyi05/winston-log-rotate-reconfiguration-issue/blob/master/index.js
What do you expect to happen instead?
winston
creates a new stream and handles reconfiguration.
Note
Alternatively, instead of reconfiguring winston
a new instance can be created, in case someone else has the same issue. Just call .close
on the old instance and create a new from scratch.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:16
- Comments:22 (2 by maintainers)
Top Results From Across the Web
Designing Error Messages and a Logging Strategy in Node.js
Learn how to structure helpful error messages and follow a good logging strategy.
Read more >"write after end" error in a server made with nodejs
The problem is that when I try to test it, it always crashes the server with an "error: write after end". Can anyone...
Read more >A Complete Guide to Winston Logging in Node.js - Better Stack
Learn how to start logging with Winston in Node.js and go from basics to best practices in no time.
Read more >Access and Error Logs - The Ultimate Guide To Logging - Loggly
Access and Error Logs. Log Files. An Apache log is a record of the events that have occurred on your Apache web server....
Read more >tslog - Extensible TypeScript Logger for Node.js and Browser ...
Extensible TypeScript Logger for Node.js and Browser: Dependency free, Fully customizable, Pretty errors, stack traces, and JSON output to attachable ...
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
Still happen in 3.3.3
tl;dr Pass by reference in logger.add() function causes the transport object to be altered and thus invalidated when used again in logger.configure()
I think I found the cause of this issue, stemming from the logger.add() function:
I added my own print statements to keep track of the target object. As can be seen in output from the print statements; the target object is edited after it is used for piping. Since target is equivalent to the transport parameter through pass by reference, the change to target also changes the transport object and thus makes it invalid for reuse in logger.configure(). This explains why an entirely new but identical transport would work with configure() but editing the original transport would give the error.
Probable Solution: Make a deep copy of the passed in transport object so that the target object is pass by value
This is my first time commenting on an open issue on GitHub so please let me know if I missed anything that would make this more helpful. I would have tried to create a coded solution myself but since object cloning doesn’t seem to be a native tool in JavaScript I figured it would be better for someone with more knowledge of the code base to create an actual solution