Skip to content
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

Compress with .gz extention #5

Closed
alainm opened this issue Jul 22, 2016 · 4 comments
Closed

Compress with .gz extention #5

alainm opened this issue Jul 22, 2016 · 4 comments

Comments

@alainm
Copy link

alainm commented Jul 22, 2016

I am trying to use rotating-file-stream with Hapi.js and good.

My trouble is that the compresses files don't have a .gz extention and that makes most Linux utilities confuzed.
If I change the compress string to add '.gz', the file with the same name is not deleted but it's size is set to zero !!! I expected the file to be deleted.
BTW: the docs say not to delete source file, I tried it and strage errors happen (as expected)

This is the relevant part of my setup:

      {
        module: 'rotating-file-stream',
        args: [
          'nodejs-web.log',
          {
            path: './logs',
            size: '10K',
            interval: '1m',
            compress: function( source, dest) {
              return 'cat ' + source + ' | gzip -c9 > ' + dest + '.gz';
            }
          }
        ]
      }

This is what I get:

ls -l
-rw-rw-r-- 1 user user 1347 Jul 22 20:32 20160722-2032-01-nodejs-web.log.gz
-rw-rw-r-- 1 user user    0 Jul 22 20:44 20160722-2043-01-nodejs-web.log
-rw-rw-r-- 1 user user 1207 Jul 22 20:44 20160722-2043-01-nodejs-web.log.gz
-rw-rw-r-- 1 user user    0 Jul 22 20:44 20160722-2044-01-nodejs-web.log
-rw-rw-r-- 1 user user 1263 Jul 22 20:44 20160722-2044-01-nodejs-web.log.gz
-rw-rw-r-- 1 user user 7107 Jul 22 20:44 nodejs-web.log
@alainm
Copy link
Author

alainm commented Jul 23, 2016

Hi, I found a way to solve this...
I Modified the compress function like this:
(I am also deleting files with more then 30 days)

            compress: function (source, dest) { // Modified compress function, add extension .gz
                                                // Also removes logs older than 30 days
              return 'cat ' + source + ' | gzip -c9 > ' + dest + '.gz; rm -f ' + dest +
                     '; find ./logs/* -mtime +30 -delete';
            }

I am leaving this open for anyone to tell a better way to add the .gz extension

@iccicci
Copy link
Owner

iccicci commented Oct 17, 2016

Have you tried to use a different file name generator function ?

The way to change file names is to use an appropriate generator .
https://github.com/iccicci/rotating-file-stream#function-filenametime-index

@iccicci
Copy link
Owner

iccicci commented Nov 3, 2016

Closing due to lack of feedback

@iccicci iccicci closed this as completed Nov 3, 2016
@ChristopherWilcoxen
Copy link

Since it took me a while to understand what iccicci meant by "Have you tried to use a different file name generator function?", I just wanted to elaborate and say he means if you're using compression and want the extension, add ".gz" to your returned file name in the generator function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants