Kermit icon indicating copy to clipboard operation
Kermit copied to clipboard

Feature request: log to files

Open rocketraman opened this issue 1 year ago • 4 comments

Sometimes it is useful to log on Android and iOS to files, which can easily be zipped up and transferred for remote analysis.

Now that kotlinx-io has been released and supports multiplatform filesystem writes (via okio, and works at least for most platforms including Android and iOS), it would be great if Kermit would leverage this to provide filesystem writing capability out of the box, rather than having users roll their own LogWriters.

For a logging tool, it would be useful also to support automatic roll-overs and deletion of older logs.

rocketraman avatar Oct 11 '24 20:10 rocketraman

Any thoughts on good models for this with other logging libraries? For mobile, do other logging libraries have default folders to store to and any kind of built-in functionality for wrapping up files? Probably nothing with actually sending them, but I could see returning a file reference to the zip.

It would be easier to essentially replicate an existing library that people seem to use vs writing something entirely new.

kpgalligan avatar Oct 15 '24 16:10 kpgalligan

My gold standard for this would likely be the Log4j2 RollingFileAppender but that is far more "full-featured" than I would expect from Kermit.

I've implemented something custom locally which takes in a Path and file name prefix as constructor params, as well as a simple configuration that specifies how big each log file can be before it is rolled, and the number of files to keep. I can start a PR with this implementation if that seems interesting.

This simplistic approach seems to be sufficient for my current needs.

rocketraman avatar Oct 15 '24 16:10 rocketraman

If you have a rough structure in mind, yeah, a PR would be good. I'd probably release this as another module rather than directly in kermit-core, at least to start. It can be focused more on mobile, or at least platforms that would support files easily (not JS).

kpgalligan avatar Oct 15 '24 16:10 kpgalligan

@kpgalligan Created PR https://github.com/touchlab/Kermit/pull/406.

rocketraman avatar Oct 16 '24 12:10 rocketraman