Comments (12)
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.
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.
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.
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.
No, there's no reason. Was just my choice. I'll add the option due your request.
Thank you
from rotating-file-stream.
+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.
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.
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.
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.
from rotating-file-stream.
I just released v1.1.0
This should solve the problem
from rotating-file-stream.
Closing due to lack of feedback
from rotating-file-stream.
Related Issues (20)
- [bug] File not rotating when using a generator function HOT 6
- [bug] the process deleted all log file when default file size larger than maxSize HOT 1
- Question: how to set folder to store file? HOT 1
- I am using node version 18 but still getting this error HOT 1
- Import error in node 20.11 HOT 8
- Cannot find module 'fs/promises' HOT 6
- Not able to compress log file HOT 3
- [bug] Cannot read properties of undefined (reading 'write') HOT 25
- Rotating log file with size, maxFiles and path options HOT 9
- Unhandled Error, No such file or directory, unlink called twice on same file. HOT 17
- The first rotated file is not specified time length. HOT 1
- Error: this.timeout.unref is not a function HOT 10
- while deploying the project i am getting this error please help HOT 7
- [bug] it does not create the file again when it's writing HOT 1
- Custom compressed file names HOT 4
- how do i do the unit testing in node js HOT 2
- Sometimes crashes on interval change HOT 3
- UTC: interval & intervalBoundary HOT 1
- Jumping from Node v14 to v18 between 3.1.1 and 3.2.0 HOT 6
- maxfiles seems to cause an error: Error: ENOENT: no such file or directory HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rotating-file-stream.