ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
957 stars 34 forks source link

Adding log appender #99

Closed kxmpxtxnt closed 11 months ago

kxmpxtxnt commented 1 year ago

Hey, is it possible to inject/add a log appender for writing the messages in a log file?

ajalt commented 1 year ago

It's possible, but not currently built in. You can implement a TerminalInterface that prints to whatever file you'd like in addition to stdout, then use your interface with the terminal like Terminal(terminalInterface=MyInterface().

For reference, here's the default interface that writes to stdout/stderr, and here's an interface that writes to memory instead of stdout