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
i want to delete log files myself, what should i do? #1111
Comments
|
eg:
|
|
This seems to be similar to #711 (comment). Is there a use-case as to why you would need to manually delete those files when In any case, const log4js = require('log4js');
log4js.configure({
appenders: {
'out': { type: 'stdout' },
'everything': {
type: 'dateFile',
filename: 'logs/trace.log',
pattern: 'yyyy-MM-dd-hhmmss',
keepFileExt: true,
numBackups: 30 // total 31 files (1 hot + 30 backups)
}
},
categories: {
default: { appenders: [ 'out', 'everything' ], level: 'debug'}
}
});
const logger = log4js.getLogger();
let count = 1;
let timer = setInterval(() => {
logger.warn("testing", count);
let dirList = fs.readdirSync("logs");
console.log("[current] dirList in logs:", dirList);
if (count >= 5) { // spam 5 times
clearInterval(timer);
// existing files
logger.warn("testing", count, "- deleting");
const fileToDelete = path.join("logs", dirList[0]);
console.log("file to delete:", fileToDelete);
// delete 1 old file
fs.unlinkSync(path.join("logs", dirList[0]));
dirList = fs.readdirSync("logs");
console.log("[deleted] dirList in logs:", dirList);
}
count++;
}, 1000); |
i think it's the same problem... i want put the log file to server, and the server read log file content,and save content to elk.so i want delete files when the files have put to server... |
@iguxiaobei Which version of This issue would also occur (on Windows) in log4js <= 6.3.0 if To delete the files programmatically via NodeJS on Windows, you have to ensure all file handlers are closed. If you are using
If you really want to, albeit destructive, you can call log4js.shutdown(() => {
// read/save/delete code here
log4js.configure(options);
}); |
@iguxiaobei, does the comment above resolve your issue? |
i think it has resolved,thank you,i will close this issue. |
I want to delete log files myself, What should i do?
I use electron, and I want to start a intervel task to delete the log files myself, but It seems like that i have no permission to do this. first time, I can delete old logs, but second time, I can't delete new files.
The text was updated successfully, but these errors were encountered: