Rcomian / bunyan-rotating-file-stream

Is an endpoint for bunyan that lets you control how much disk space logs take.
Other
29 stars 15 forks source link

What causes rotation to create duplicate files. #41

Closed itsgratien closed 12 months ago

itsgratien commented 1 year ago

Hello,

I would like to know why bunyan-rotating-file-stream create duplicate files but different those file on filename. where it adds .1.log or .2.log for example during rotation it created the following ones on production:

  1. info-2023-10-10.log
  2. info-2023-10-10.1.log
  3. info-2023-10-10.2.log
  4. info-2023-10-10.3.log

My expectation was to create only info-2023-10-10.log as it happened on my local computer.

Rcomian commented 12 months ago

This is the main reason the module exists - to do this.

It will create a new file once the limits of the main file are breached -either through age or size. It will keep old files for as long as necessary until we hit the limits on either number of files or total directory usage.

So it will create a file, write to it until it's either too big or too old, and then it will create a new file. I suspect your file got too large in production, and so started a new file. This is useful when you want to limit the overall size of logs kept - so that we don't run out of disk space. It means we can delete the oldest of the files and keep the most recent files which hopefully have the most useful data in them. Also, smaller files can be easier to manipulate, copy remotely, etc.

If it needs to create a new file but the filename would create a collision with an existing file, it starts appending a number to the filename. You can control where this number goes using %N in the formatting field.

https://github.com/Rcomian/bunyan-rotating-file-stream#rotation-number-templating-n https://github.com/Rcomian/bunyan-rotating-file-stream#filename-clashes

You can change the threshold in the options to increase the individual file size if you wish. You can change the period, which affects when the system creates a new file. Check the documentation for those in the readme as well.

Does this answer everything you need?

itsgratien commented 12 months ago

Hello @Rcomian, It definitely answer what I was looking for.

Thank you.