Example use of generator fails with "write after end" error.
See original GitHub issueThe example use of a generator function in the documentation fails with “write after end” error:
Simple program to reproduce this is:
var rfs = require('rotating-file-stream');
function pad(num) {
return (num > 9 ? "" : "0") + num;
}
function generator(time, index) {
if(! time)
return "file.log";
var month = time.getFullYear() + "" + pad(time.getMonth() + 1);
var day = pad(time.getDate());
var hour = pad(time.getHours());
var minute = pad(time.getMinutes());
return "/storage/" + month + "/" + month +
day + "-" + hour + minute + "-" + index + "-file.log";
}
var stream = rfs(generator, {
size: '1M',
interval: '30m'
});
setInterval(function () {
stream.write('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
}, 10);
Using node 8.4.0 on Bash on Windows 10.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:23 (10 by maintainers)
Top Results From Across the Web
Write after end error when launch server in nodejs
I am beginner at NodeJS and I'm doing a "NodeJS and Express.js full course" at freecodecamp yt and I copied author code which...
Read more >[core-https] "write after end" test failure on Node 14 #11919
Two tests in core-https are failing on Node 14: 1) NodeHttpsClient should report upload and download progress: RestError: write after end at ...
Read more >22. Generators - Exploring JS
As a first example, consider the following generator function whose name is genFunc : ... function * genFunc () { throw new Error...
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
Mistake #4: Expecting Callbacks to Run Synchronously Even then, these are often limited to conditional statements, loop statements, and function invocations. ...
Read more >Understanding Generators in ES6 JavaScript with Examples
Inside the function, we have an infinite while loop. In that loop, we yield the num . When the generator yields, it is...
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 Free
Top 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
Hi @normancarcamo ,
your generator function takes not care neither of parameter
index
nor of parametertime
(apart from first check).Please pay attention to the note of this paragraph: https://www.npmjs.com/package/rotating-file-stream#function-filenametime-index returned rotated file name must be function of both parameters time and index.
Hope this helps, iCC
@iccicci Thanks bro, I understand and I just did a test of what you have said and its true, but I think that using the following format “hh:mm:ss.log.(index|counter)” is enough for me (well in my case its ok), by the way my issue is gone now, it is working as I’d expect using “pipe” instead of the style “write(chunk)”, here is a copy of my rotator.js config file:
Terminal output:
And this is my logs directory:
Oh and to finish I think that using the option “initialRotation” (in my case again) works well instead of ignoring it whenever the option “rotationTime” is set to true.
😃 thanks its a great utility, I was doing this directly using logrotate utility in debian and the problem that I had there was that whenever a file is rotate and new logs arrive to be written they turn out be corrupted due to the “fd” is attached to the initial process that runs it, the solution that I was doing was stop the pid and the reenable it but it looks a bit meesy.
I was looking for packages on npm to see if there was a solution for node and I saw this 😃 and it’s doing it very well.