expressjs / morgan

HTTP request logger middleware for node.js
MIT License
7.95k stars 536 forks source link

Option to zip log files automatically #177

Closed Simran-B closed 6 years ago

Simran-B commented 6 years ago

It would be really handy if morgan could compress the logs on the fly or zipped them automatically on rotation.

winston-daily-rotate-file calls such an option zippedArchive: A boolean to define whether or not to gzip archived log files. (default 'false')

They seem to compress the logfile in one piece on rotation:

        if (options.zippedArchive) {
            this.logStream.on('rotate', function (oldFile) {
                var gzip = zlib.createGzip();
                var inp = fs.createReadStream(oldFile);
                var out = fs.createWriteStream(oldFile + '.gz');
                inp.pipe(gzip).pipe(out).on('finish', function () {
                    fs.unlinkSync(oldFile);
                });
            });
        }

I guess it would be too risky to use on-the-fly compression because in case of an abrupt process termination the file could be rendered invalid...

dougwilson commented 6 years ago

hi @Simran-B morgan does not implement any kind of file writing. This module accepts a stream option where it will write your logs out to a stream. You can use things like a transform stream to do transformations like compression on the data or file rotation, though this is all outside of morgan directly.