touchlab / Kermit

Kermit by Touchlab is a Kotlin Multiplatform centralized logging utility.
https://kermit.touchlab.co
Apache License 2.0
715 stars 41 forks source link

Feature request: log to files #405

Open rocketraman opened 1 week ago

rocketraman commented 1 week ago

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.

kpgalligan commented 5 days ago

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.

rocketraman commented 5 days ago

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.

kpgalligan commented 5 days ago

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).

rocketraman commented 4 days ago

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