# log filename in a callback plugin

**URL:** <https://forum.ansible.com/t/log-filename-in-a-callback-plugin/23660>\
**Category:** Ansible Project\
**Created:** [February 7, 2017, 10:08am UTC](https://forum.ansible.com/t/log-filename-in-a-callback-plugin/23660 "2017-02-07T10:08:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [February 7, 2017, 10:08am UTC](https://forum.ansible.com/t/log-filename-in-a-callback-plugin/23660/1 "2017-02-07T10:08:47Z")

</div>

Hello,

In a callback plugin, I did parameter the filename to dipatch log files by host and ansible pid this way:  
filename = ‘%s\_%s’ % (host,os.getpid())

I would like to add the name of the playbook that is run, in example if I run the command: ansible-playbook test.yml, I would like to create this logfile: test\__host\_pid_  
in what structure and variable can I get the playbook name ?

Regards

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [February 7, 2017, 1:11pm UTC](https://forum.ansible.com/t/log-filename-in-a-callback-plugin/23660/2 "2017-02-07T13:11:24Z")

</div>

I did modify my plugin this way:

def _init_(self):  
super(CallbackModule, self)._init_()  
**self.playbook\_name = None**

if not os.path.exists(“./logs”):  
os.makedirs(“./logs”)

- def v2\_playbook\_on\_start(self, playbook):  
self.playbook = playbook  
self.playbook\_name = os.path.basename(self.playbook.\_file\_name\*)

def log(self, host, data):  
**filename = ‘%s\_%s\_%s’ % (self.playbook\_name,host,os.getpid())**  
path = os.path.join(“./logs”, filename)
