Git Product home page Git Product logo

Comments (12)

iccicci avatar iccicci commented on June 30, 2024

You are right!

The module works as intended, I didn't thought to classical unix logrotate tool behaviour when I wrote the module.

I'll add this feature in the next days.

Thank you

from rotating-file-stream.

nickcoutsos avatar nickcoutsos commented on June 30, 2024

Thanks!

In retrospect, I thought the readme claimed the module was a replacement for the *nix logrotate utility but that was a different implementation I looked at.

I have an issue somewhat related to this one, given that I found it when considering actual rotation may not be possible:

I wanted use the following name generator:

function generateName(time, index) {
    return 'access.log' + (time ? '.' + time.toISOString() : '');
}

the problem I'm seeing is that the time supplied to my function is only ever accurate to the hour level. Was there any particular reason for that? I notice in the readme you have an example name function that includes the minute, and you even support intervals of seconds. Wouldn't it be reasonable to leave the full accuracy and let the custom function decide how granular they want the name to be?

from rotating-file-stream.

iccicci avatar iccicci commented on June 30, 2024

It seems you are using both rotation by size and rotation by interval.
In that case (as readme says) the time parameter is the start time of time rotation period, so file name generator must use both time and index parameters (I will clarify this in next readme release).

You can try a generator like this, it should solve your problem:

function generateName(time, index) {
    if(! time)
        return 'access.log';

    return 'access.'+ time.toISOString() + '.' + index + '.log';
}

Thank you again

from rotating-file-stream.

nickcoutsos avatar nickcoutsos commented on June 30, 2024

But what I'm trying to understand is if there's any reason for the time parameter to ever omit the minutes/seconds/milliseconds from the time.

The application could have the flexibility to not use that level of granularity in the generated name if that's preferable (in which case, the index would be useful/necessary).

from rotating-file-stream.

iccicci avatar iccicci commented on June 30, 2024

No, there's no reason. Was just my choice. I'll add the option due your request.

Thank you

from rotating-file-stream.

dupski avatar dupski commented on June 30, 2024

+1
It seems this module doesn't have an option to delete older log files. Could you maybe add a 'count' option to specify the maximum number of log files to keep? (an example here: https://github.com/capriza/logrotator)

from rotating-file-stream.

alainm avatar alainm commented on June 30, 2024

I managed to have rotating and gzipd files fiddling only with the compress functio (configuration for hapi.js 's good):

{
        module: 'rotating-file-stream',         // Writes to file and rotates
        args: [
          'server.log',                         // File name, rotated files get a time-stamp
          {
            path: './logs',
            size: '1M',                         // test: 10K
            interval: '1d',                     // test: 1m
            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/*server.log.gz -mtime +30 -delete';// test: -mmin +3
            }
          }

from rotating-file-stream.

marcelonidal avatar marcelonidal commented on June 30, 2024

Hi, i'm facing some problems trying to log rotate with foverer:

Note: i'm using windows SO.

This is my test.js:

'use strict';

var http = require('http');
var rfs = require('rotating-file-stream');

function pad(num) {
return (num > 9 ? "" : "0") + num;
}

function gerador(time, index) {

if(!!!time){
    let date = new Date();

    return `/${date.getFullYear()}/${pad(date.getMonth() + 1)}/${pad(date.getDate())}-0.log`;
}

return `${time.getFullYear()}/${pad(time.getMonth() + 1)}/${pad(time.getDate())}-${index}.log`;

}

var stream = rfs(gerador, {
size: '2M', // rotate every 2 MegaBytes written
interval: '5s', // rotate daily
path: 'log'
});
var i=0;
setInterval(function(){
console.log("rotate", i++);
}, 5000);

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('testing. . .\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

And my runme.bat:

@echo off
cls
@echo __________________________________
@echo - S T A R T I N G N O D E -
@echo -__________________________________-

set year=%date:~-4%
set month=%date:~3,2%
set day=%date:~0,2%

if not exist "./log/%year%/%month%/" mkdir "log/%year%/%month%/"

:menu
set m={}
echo.
set /p m=1 start or 2 stop then press enter:
if %m%=={%1}=={} goto menu
if %m%==1 goto 1
if %m%==2 goto 2
@echo.
@echo __________________________________________
@echo - E N T E R A V A L I D K E Y ! -
@echo -__________________________________________-
goto menu

:1
@echo.
forever start -p log/%year%/%month%/ -a -l %day%-0.log test.js
goto menu

:2
@echo.
@echo _________________________________________________
@echo - S T O P P I N G S E R V I C E -
@echo -_________________________________________________-
forever stop test.js
goto end

:end

exit

So, everything looks fine (the files are created successfully), but the output is only going to file 17-1.log. The 17-0, 17-2, 17-3 ... are empty.

What i shoud do to keep the historical in these files?

Thank you!

from rotating-file-stream.

iccicci avatar iccicci commented on June 30, 2024

Hi guys, I'm sorry for my absence, but I've been so busy in the last months.
I'll try to fix this.

As quick reply for last message: it seems you never used stream.write() so how do you expect some data in the file? I strongly recommend you a deeper read of README, it seems you are missing many important aspect of module interface.

from rotating-file-stream.

marcelonidal avatar marcelonidal commented on June 30, 2024

from rotating-file-stream.

iccicci avatar iccicci commented on June 30, 2024

I just released v1.1.0
This should solve the problem

from rotating-file-stream.

iccicci avatar iccicci commented on June 30, 2024

Closing due to lack of feedback

from rotating-file-stream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.