tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Allow tracing-appender sized log and rotation

Open IniterWorker opened this issue 3 years ago • 7 comments

Feature Request

Crates

The tracing-appender

Motivation

In a constraint environment, we should be able to contain the logging size and period. Let's say we want temporary logging in tmpfs, we are not able to manage the size of the log file or the rotation pool size.

Proposal

We should create a new rotate_sized mod with all the sized logic.

  • The ability to rotate log files based on a maximum size (rather than duration)
  • A configuration to limit the maximum number of previous log files to keep, and delete older ones.
  • An option to create a symlink to the latest log file, and update it when log files are rotated.
-- logs
   --- log (sym link -> current log)
   --- log.0
   --- log.1
   --- log.2 (maximum set 3)

Alternatives

We could improve the rolling. But, it seems to make simple things more complicated.

IniterWorker avatar Feb 18 '22 13:02 IniterWorker

If I understand correctly, this issue is proposing a few features:

  • The ability to rotate log files based on a maximum size (rather than duration)
  • A configuration to limit the maximum number of previous log files to keep, and delete older ones.
  • An option to create a symlink to the latest log file, and update it when log files are rotated.

I would be very happy review to pull requests that add all of these features, and I can provide some guidance for implementing them.

Also, note that there was a previous feature request specifically for size-based file rotation, #858. I believe there was also an attempt to implement it at the time, but there were some issues with the implementation.

hawkw avatar Feb 18 '22 19:02 hawkw

Hi @hawkw,

I updated the issue with your summary. Thank you by the way.

The search engine didn't come with #858 . I will look into it.

No time for me right now, maybe few weeks,

B. R

IniterWorker avatar Feb 19 '22 00:02 IniterWorker

Hi! I have the exact same needs.

I would be very happy review to pull requests that add all of these features, and I can provide some guidance for implementing them.

My company allowed me to get an initial implementation for that done on my working hours, and it would be a pleasure for me to send pull requests. I did read a bit the code of the rolling module, but any additional guidance would be greatly appreciated to get started faster 🙂

Thank you!

CBenoit avatar Jun 07 '22 20:06 CBenoit

Hi @CBenoit, thanks for your interest in contributing this change! Are there specific aspects of the implementation that you have questions about?

From the API side, I think at some point, as more features are added to the rolling file appender, we'll probably want to add a builder-style interface for configuring the rolling file appender's behavior. For this change, though, I think we'll want to add a new Rotation type for size-based rotation.

hawkw avatar Jun 07 '22 20:06 hawkw

Hi @CBenoit, thanks for your interest in contributing this change! Are there specific aspects of the implementation that you have questions about?

Rather than questions about aspects of the current implementation, I would like to know more about how you envisioned this feature (even a rough idea). For instance, if you have a specific API, or specific implementation in mind? Maybe it’s simpler to just go ahead and open a draft PR though. For the API side, I was thinking about adding a whole new API surface using some kind of builder pattern as you suggested.

For this change, though, I think we'll want to add a new Rotation type for size-based rotation.

So if I understand correctly, you suggest to create a completely different Rotation type, maybe inside of its own module rotate_sized as suggested by OP? Since Rotation is currently opaque we could also change the internal representation to allow for more complex combinations (timed only, sized only, timed AND sized, file name format, symlink, delete older files…).

CBenoit avatar Jun 08 '22 01:06 CBenoit

I opened a pull request to address the following point:

The ability to rotate log files based on a maximum size (rather than duration)

This pull request already addressed the following point:

A configuration to limit the maximum number of previous log files to keep, and delete older ones.

In order to track progress efficiently, I suggest creating a separate issue for the remaining point:

An option to create a symlink to the latest log file, and update it when log files are rotated.

I intend to tackle this last point as well.

CBenoit avatar Mar 04 '23 02:03 CBenoit