-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reopen the log files, Error: write after end #33
Comments
I also tried to fix the 'write after end' as below. Thoughts? +exports.stream
+
exports = module.exports = function morgan(format, options) {
if (typeof format === 'object') {
options = format
@@ -56,12 +58,12 @@
var fmt = compile(exports[format] || format || exports.default)
// options
- var stream = options.stream || process.stdout
+ exports.stream = options.stream || process.stdout
, buffer = options.buffer;
// buffering support
if (buffer) {
- var realStream = stream
+ var realStream = exports.stream
var buf = []
var timer = null
var interval = 'number' == typeof buffer
@@ -79,7 +81,7 @@
}
// swap the stream
- stream = {
+ exports.stream = {
write: function(str){
if (timer === null) {
timer = setTimeout(flush, interval)
@@ -99,7 +101,7 @@
if (skip(req, res)) return;
var line = fmt(exports, req, res);
if (null == line) return;
- stream.write(line + '\n');
+ exports.stream.write(line + '\n'); |
No, I want to stop having globals on the export. The answer is you cannot close the write stream until you stop accepting requests on your http server (i.e. wait for server.close to callback). |
As a side thought, if you cannot close the write stream until you stop accepting requests, how would one go about implementing daily log file rotation? It doesn't seem practical to shut down your server every night at a specified time just so you could start a new log file. |
For log rotation, the stream itself would implement that. You can find file rotation streams on npm like https://www.npmjs.org/package/rotate-file-stream |
I tried to reopen the log files but I got 'Error: write after end'.
Does morgan have the function for reopening logger?
The text was updated successfully, but these errors were encountered: