How to set ansible facts to logs

I have a scenario where I am executing my Ansible playbook with Jenkins. I have to save the execution output in a txt file which the ansible itself should generate.

The naming convention of the log file should be like _< Jenkins build number >.json.

The log should contain the exact status of the execution. If the execution failed then the failure reason should go to logs and if it is successful then what tasks get executed successfully should go to logs.

Does anyone know how to do this?

The simplest way would be a callback, the `tree` callback already does
something similar, I don't know if any of the existing do exactly what
you want, but it should be easy to modify the `tree` one to do so.

Can you share any web-link where I can find more information regarding tree and more details.

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/tree_callback.html