how to append to log file
See original GitHub issueHi megahertz,
when my electron app restarts, it’s overriding the old log file. I want append the new logging data to the old log file. How can I do this?
I’m using ubuntu 14.04.
here is my code:
const electron = require('electron');
const log = require('electron-log');
const app = electron.app;
const ipcMain = electron.ipcMain;
...
log.transports.file.level = 'debug';
log.transports.file.maxSize = 15 * 1024 * 1024;
log.transports.file.file = __dirname + '/app.log';
log.transports.file.streamConfig = { flags: 'w' };
log.transports.file.stream = fs.createWriteStream(log.transports.file.file);
log.transports.console.level = 'debug';
...
app.on('ready', function() {
log.info('start app');
...
}
I read this: “Modifying a file rather than replacing it may require a flags mode of r+ rather than the default mode w” at: https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options
and tried this:
log.transports.file.streamConfig = { flags: 'r+' };
and ‘a’ too
but it dosn’t solved the problem. What have I to do, to make it work?
Thank you for your help
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to append content to an existing log file without ...
Use >> to append, instead of > .
Read more >logappend (Append Log File) - Windows drivers
The .logappend command appends a copy of the events and commands from the Debugger Command window to the specified log file.
Read more >appender_file: Append log messages to a file in logger - Rdrr.io
The renaming happens recursively (eg logfile.1 renamed to logfile.2) until the specified max_files, then the oldest file (logfile.
Read more >Linux append text to end of file - nixCraft
Open the terminal application · Append text to end of file using echo command: echo 'text here' >> filename · Append command output...
Read more >Append to the top in a log file - shell script
the variable $LOGFILE is where the script append every single statement of the process. Thanks :) Basically want I'd like to to do...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pbmzero I did it in this way:
log.transports.file.stream = fs.createWriteStream(log.transports.file.file, { flags: 'a' });
in your case, maybe this is better (to not repeat your self):
log.transports.file.stream = fs.createWriteStream(log.transports.file.file, log.transports.file.streamConfig);
Thanks a lot !