nuclear icon indicating copy to clipboard operation
nuclear copied to clipboard

Use a rotating log file in addition to logging to the console

Open nukeop opened this issue 1 year ago • 19 comments

The log file needs to be stored in the same directory as the config files and never exceed 1-2MB.

nukeop avatar Dec 04 '23 17:12 nukeop

Can you please provide few more details about this issue, i am new here so i would love to contribute on this @nukeop

Tweniee avatar Dec 05 '23 11:12 Tweniee

The logs from the main process and the renderer process need to be saved to a file with a capped size. When the limit is reached, a new file needs to be created. When the limit in that file is reached, the next log should clear the oldest log file and start saving there. The number of log files and the limit should both be customizable.

nukeop avatar Dec 05 '23 11:12 nukeop

The number of log files and the limit should both be customizable.

and from where it should be controlled?

Tweniee avatar Dec 05 '23 12:12 Tweniee

For now, it can be hardcoded in the logger initialization code.

nukeop avatar Dec 05 '23 12:12 nukeop

Hi @Tweniee, are you still working on this issue?

RyanMurphy1014 avatar Jan 16 '24 00:01 RyanMurphy1014

Can I work on this if it is not resolved yet? Looks like there has been no activity since a while

thathva avatar Mar 01 '24 18:03 thathva

Sure, go ahead!

nukeop avatar Mar 01 '24 20:03 nukeop

Hey @nukeop! I was a bit occupied trying to set the dev environment and was able to set it up. I have couple of questions about the requirements. If I understood it right:

  1. Have some hardcoded config in the index.ts file in the logger component in the main package.
  2. Have a check that if the specified limit has been exceeded, create new files and start saving to this file. My question is what would happen to the older files? Would we be overwriting those files or just leave it to the user to clean it up if necessary?
  3. By logs, does it include all logs like errors, warnings and events?

thathva avatar Mar 07 '24 01:03 thathva

We're using electron-timber to differentiate logs coming from the main and renderer processes. Don't implement your own rotation system, see if you can use an existing package and integrate it with timber. Whatever timber logs should be saved into the log file. I think a decent default will be 3 files, 1MB each, when the last log reaches its limit, start saving to the first one again.

nukeop avatar Mar 07 '24 10:03 nukeop

Got it! Thanks, will let you know if I have any more questions.

thathva avatar Mar 07 '24 18:03 thathva

The rotating-file-stream package seems to have the functionality of maxFiles and a custom generator function that can be used to "rotate" files. All it needs is an index. I have tried it on a high level and it seems to create the new files of upto the specified size limit. I am yet to figure out passing the index and rewrite to the older log files (it uses timestamps as of now). Does this sound like a good approach so far? (https://www.npmjs.com/package/rotating-file-stream#filenametime-index)

thathva avatar Mar 08 '24 00:03 thathva

Sounds good if you can make it work with the current logging mechanism.

nukeop avatar Mar 08 '24 01:03 nukeop

I think this task can be taken up by any other person that is available. I am having a difficult time with the development environment, even though I am on Linux (mostly system specifications - low end PC). My findings that can help anyone:

I wasn't able to find any library that does the rotation, by files at least. I was able to make it work a little bit with the rotating-file-stream library itself, but that still needs more customization in the custom function to generate new files. The library does create new files, but the index was getting messed up, so it would create way too many files.

thathva avatar Mar 14 '24 23:03 thathva

Hey @nukeop, I am new here and would like to work on this issue if it is still available. As of right now, I am thinking to continue @thathva's approach with using the rotating-file-stream and try to get the index to work properly in the generate function.

Kiduzk avatar Apr 21 '24 15:04 Kiduzk

Okay! There's been a bunch of people announcing they're working on this, then doing nothing. I think we've got the approach down already. All that's needed is a pull request, in any shape - we can iterate the solution.

nukeop avatar Apr 21 '24 22:04 nukeop