Winston: file rotation not working properly

Created on 21 Oct 2014  Â·  9Comments  Â·  Source: winstonjs/winston

@indexzero and @FotoVerite and @Marak Squires

i hve maxFile :10 ,so it create 10 files(1,2,3,4,5,6,7,8,9,10) and after 10 in replace 1 as 11 and so on it goes ,upto this ok.

i have run my server again it star from 1 to 10, already present log file number was (20 to 30 ) rotation reach 20 i will start from 31 ,32

what happens my new 10 files(11 to 20) ,why it kept 20 to 30 from the last server run ?

investigate

Most helpful comment

Hi, Winston is great! But I've seen some odd behaviour with the logger.transports.File transport too.

I did some testing with maxFiles=5 and a small maxFileSize so I could trigger rotation easily. This is what I saw.

Start up app.

  • Logs to foo.log
  • Logs to foo1.log
  • Logs to foo2.log
  • Logs to foo3.log
  • Logs to foo4.log
  • Deletes foo.log and logs to foo5.log
  • Deletes foo1.log and logs to foo6.log
  • Deletes foo2.log and logs to foo7.log

Restart app (at this point, foo3.log - foo7.log exist)

  • Logs to foo.log
  • Logs to foo1.log
  • Logs to foo2.log (at this point, foo.log and foo1.log - foo7.log exist, mixing new and old)
  • Deletes foo.log, foo1.log and foo3.log, logs to foo8.log (deleted a recent log. at this point, foo2.log and foo4.log - foo8.log exist)
  • Deletes foo5.log, logs to foo9.log
  • Deletes foo6.log, logs to foo10.log

Restart app (at this point, foo2.log and foo6.log - foo10.log exist)

  • Logs to foo.log
  • Logs to foo1.log
  • Logs to foo3.log (mixed old and new logs)
  • Logs to foo4.log
  • Deletes foo.log, logs to foo5.log
  • Deletes foo1.log, foo2.log, foo3.log, foo4.log and foo6.log, logs to foo11.log (deleted several recent logs)
  • Deletes foo7.log, logs to foo12.log

I've highlighted what I think are problems in bold - deleting newer instead of older logs, keeping more logs than maxFiles, mixing older and newer logs.

As a general approach, could Winston's file transport mimic the log rotation behaviour that linux logrotate uses? I.e.:

  • First log file is foo.log, next oldest is foo1.log, next oldest is foo2.log, etc
  • When rotating files, rename foo.log to foo1.log, foo1.log to foo2.log, and delete the last one if it exceeds our maxFiles setting?

I think it would be simpler for people to understand this behaviour.

All 9 comments

Hi @mohamedmohsin,

First of all, thanks for reporting. Do you think you can share a snippet showing this behavior?

Thanks in advance,

Hi, Winston is great! But I've seen some odd behaviour with the logger.transports.File transport too.

I did some testing with maxFiles=5 and a small maxFileSize so I could trigger rotation easily. This is what I saw.

Start up app.

  • Logs to foo.log
  • Logs to foo1.log
  • Logs to foo2.log
  • Logs to foo3.log
  • Logs to foo4.log
  • Deletes foo.log and logs to foo5.log
  • Deletes foo1.log and logs to foo6.log
  • Deletes foo2.log and logs to foo7.log

Restart app (at this point, foo3.log - foo7.log exist)

  • Logs to foo.log
  • Logs to foo1.log
  • Logs to foo2.log (at this point, foo.log and foo1.log - foo7.log exist, mixing new and old)
  • Deletes foo.log, foo1.log and foo3.log, logs to foo8.log (deleted a recent log. at this point, foo2.log and foo4.log - foo8.log exist)
  • Deletes foo5.log, logs to foo9.log
  • Deletes foo6.log, logs to foo10.log

Restart app (at this point, foo2.log and foo6.log - foo10.log exist)

  • Logs to foo.log
  • Logs to foo1.log
  • Logs to foo3.log (mixed old and new logs)
  • Logs to foo4.log
  • Deletes foo.log, logs to foo5.log
  • Deletes foo1.log, foo2.log, foo3.log, foo4.log and foo6.log, logs to foo11.log (deleted several recent logs)
  • Deletes foo7.log, logs to foo12.log

I've highlighted what I think are problems in bold - deleting newer instead of older logs, keeping more logs than maxFiles, mixing older and newer logs.

As a general approach, could Winston's file transport mimic the log rotation behaviour that linux logrotate uses? I.e.:

  • First log file is foo.log, next oldest is foo1.log, next oldest is foo2.log, etc
  • When rotating files, rename foo.log to foo1.log, foo1.log to foo2.log, and delete the last one if it exceeds our maxFiles setting?

I think it would be simpler for people to understand this behaviour.

any update about log rotation of winston ?

I've got the same issue still in End 2016. We have a long term running app with logs > 100... After restart we got at doubled log files in count. I'd appreciate any change here to mimic linux logrotation as mentioned before!

+1

    -rw-r--r-- 1 1049089 5245600 Nov 22 13:17 guiserver2.log
    -rw-r--r-- 1 1049089 5245680 Nov 22 13:18 guiserver3.log
    -rw-r--r-- 1 1049089 5245326 Nov 22 13:18 guiserver4.log
    -rw-r--r-- 1 1049089 5245680 Nov 22 13:18 guiserver5.log
    -rw-r--r-- 1 1049089 1169872 Nov 22 13:18 guiserver6.log
    -rw-r--r-- 1 1049089 5245502 Nov 22 13:16 guiserver48.log
    -rw-r--r-- 1 1049089 5244624 Nov 22 13:17 guiserver49.log
    -rw-r--r-- 1 1049089 5244622 Nov 22 13:17 guiserver50.log
    -rw-r--r-- 1 1049089 5245856 Nov 22 13:17 guiserver51.log
    -rw-r--r-- 1 1049089 2164448 Nov 22 13:17 guiserver52.log

What's the status on this four years later? I'm seeing the same issues and I'm losing log entries because of it. I have an app that starts up once a day, logs a bunch of data, then shuts down. I have maxFiles set to 30 and it's only using 5 or 6 of them per run. By the end of the run I'm missing log entries from the beginning.

Use logrotate

https://linux.die.net/man/8/logrotate

On Fri, Aug 24, 2018 at 4:17 PM David Land notifications@github.com wrote:

What's the status on this four years later? I'm seeing the same issues and
I'm losing log entries because of it. I have an app that starts up once a
day, logs a bunch of data, then shuts down. I have maxFiles set to 30 and
it's only using 5 or 6 of them per run. By the end of the run I'm missing
log entries from the beginning.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/winstonjs/winston/issues/477#issuecomment-415871049,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAERe2xpSbl03mhLputRMnkkeeJHvn2uks5uUF9DgaJpZM4CxIxb
.

I ended up using this transport. Pretty easy to use and seems to work well.

Yes, the daily file rotate transport is recommended. Logrotate works too but it’s nice to stay within the Winston ecosystem :)

Going to close this, but if anyone has reproducible issues with the File transport, feel free to open a fresh issue. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pocesar picture pocesar  Â·  3Comments

amiram picture amiram  Â·  4Comments

mohanen picture mohanen  Â·  4Comments

Tonacatecuhtli picture Tonacatecuhtli  Â·  4Comments

JaehyunLee-B2LiNK picture JaehyunLee-B2LiNK  Â·  3Comments