Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to programmatically set the log file path? #654

Closed
lizhongyue248 opened this issue Jan 13, 2024 · 2 comments
Closed

How to programmatically set the log file path? #654

lizhongyue248 opened this issue Jan 13, 2024 · 2 comments

Comments

@lizhongyue248
Copy link

I want to set the path of the log file in my program instead of through the configuration file.

Configuration file like :

writer=console
writer.format={date: HH:mm:ss.SSS} {pid} {level} [{thread}] {class}.{method}:{line} - {message}
# ------------------------------------------------------------------------------
writer2=file
writer2.file=logs/port-view.log
writer2.level=info
writer2.format={date: HH:mm:ss.SSS} {pid} {level} [{thread}] - {message}
writer2.charset=UTF-8

How do I change the writer2.file in my program when user input path?

TextField(
    value = filtPathState,
    onValueChange = {
        filtPathState.value = it
        // Change log file path.....
    },
)

Thanks!

@lizhongyue248 lizhongyue248 changed the title How to programmatically set the log file name? How to programmatically set the log file path? Jan 13, 2024
@pmwmedia
Copy link
Member

You can set writer2.file programmatically. However, you have to be aware that tinylog's configuration becomes immutable as soon as the first log entry is issued. This behavior allows tinylog to process log entries with disabled severity levels way faster than other logging frameworks: https://tinylog.org/v2/benchmark/#discarding-log-entries

How to set writer2.file programmatically:

Configuration.set("writer2.format", "<your path>");

@lizhongyue248
Copy link
Author

Thanks!It works very well!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants