'snakemake: access workdir from inside log_handler script

I am trying to create a custom log_handler script that can save the workflow´s log as a JSON file inside {workdir}/logs. For that I need to know what is the current workdir but I cannot seem to access is from inside the script. Does anyone know how to access workdir from inside a log_handler script?

I have also tried using Path.cwd() from inside the script, but it did not work.

EDIT: to clarify this a bit more, snakemake allows to specify a --log-handler-script. According to the documentation:

Provide a custom script containing a function ‘def log_handler(msg):’. Snakemake will call this function for every logging output (given as a dictionary msg) allowing to e.g. send notifications in the form of e.g. slack messages or emails.

I am trying to write such a script (based on this) that parses the log messages and saves them in a file, ideally, inside the workdir. But for that, the script needs to be able to know the current workdir.

thanks,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source