# An example callback for logging per-host activity in /var/log/ansible

**URL:** <https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818>\
**Category:** Ansible Project\
**Created:** [August 21, 2012, 10:45pm UTC](https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818 "2012-08-21T22:45:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 21, 2012, 10:45pm UTC](https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818/1 "2012-08-21T22:45:29Z")

</div>

Recently someone (believe it was Lorin, can't remember) was asking  
about whether we could log activity on a per host basis on the server  
-- given, we already log things remotely on the client.

Now, everyone is going to want different kind of logs, so I didn't  
want to work this into core, but I made a callback plugin.

This may be exactly what you want, it may not be, but the niceness is,  
you can tweak it however you want, and it's not part of core, so you  
don't have to fork ansible and maintain a different implementation.

I hope this is useful in showing what callback plugins can do, and  
helps people write other plugins:

[https://github.com/ansible/ansible-plugins/blob/master/callbacks/log\_plays.py](https://github.com/ansible/ansible-plugins/blob/master/callbacks/log_plays.py)

--Michael

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [August 23, 2012, 2:31am UTC](https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818/2 "2012-08-23T02:31:56Z")

</div>

I don’t know if it was me that mentioned this, but the next time I do ansible-related stuff, I’m definitely going to use the new callback hooks to generate some log files with the returned error strings properly formatted (e.g.,. no inline “\n” stuff)

Take care,

Lorin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 23, 2012, 3:07am UTC](https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818/3 "2012-08-23T03:07:32Z")

</div>

We didn't really have log files before, so I'm kind of confused as to what you were not happy about.

The logging callback here is very much a proof of concept, I'll take upgrades to it.

--Michael

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [August 23, 2012, 3:14am UTC](https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818/4 "2012-08-23T03:14:51Z")

</div>

I was just referring to the console output that gets generated by ansible-playbook when a task fails not he client. So, for example, if I’m installing a bunch of packages with the pip module, and something fails, a lot of output gets dumped back, but it’s not really readable unless the “\n”'s are turned into proper newlines.

I’ll try out these callbacks once I start hitting this stuff again.

Take care,

Lorin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 23, 2012, 12:21pm UTC](https://forum.ansible.com/t/an-example-callback-for-logging-per-host-activity-in-var-log-ansible/11818/5 "2012-08-23T12:21:47Z")

</div>

That's actually not user-pluggable and would need to go in core,  
though all it would require is writing a custom JSON pretty-printer.

I've been thinking about that -- there's really no reason that output  
even needs to be json, so one key per line, or equivalent, would be  
reasonable for playbook output.
