question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to append to log file

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SebastianDettmanncommented, May 13, 2018

@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);

0reactions
JessicaIpocommented, Dec 12, 2019

Thanks a lot !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found