# How to log something in a custom module ?

**URL:** <https://forum.ansible.com/t/how-to-log-something-in-a-custom-module/30786>\
**Category:** Ansible Project\
**Created:** [July 15, 2019, 2:40pm UTC](https://forum.ansible.com/t/how-to-log-something-in-a-custom-module/30786 "2019-07-15T14:40:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hackcurly](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@Hackcurly](https://forum.ansible.com/u/Hackcurly)\
**Post date:** [July 15, 2019, 2:40pm UTC](https://forum.ansible.com/t/how-to-log-something-in-a-custom-module/30786/1 "2019-07-15T14:40:02Z")

</div>

Hi,

I would like to know how to log some variable or other useful information directly in the “Ansible log” displayed when using “-vvvv”.

I tried Display(), but it seems to be not in the same “context”.

So what do you advice for log information into a custom module ?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 15, 2019, 2:48pm UTC](https://forum.ansible.com/t/how-to-log-something-in-a-custom-module/30786/2 "2019-07-15T14:48:52Z")

</div>

You have to be a more specific, modules have several ways of returning  
information back to the controller vs 'logging' information (  
`AnsibleModule.log()` method should handle that to the local remote  
system). If you want to return information back to the controller you  
can just make it part of the results the module returns, you can also  
use module methods to issue warnings or deprecations.

---

<div class="post-metadata">

**Author:** ![Hackcurly](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@Hackcurly](https://forum.ansible.com/u/Hackcurly)\
**Post date:** [July 16, 2019, 2:02pm UTC](https://forum.ansible.com/t/how-to-log-something-in-a-custom-module/30786/3 "2019-07-16T14:02:34Z")

</div>

What I would like to do it’s like this debut output :

TASK [Get system] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/user/playbooks/pb\_banner.yml:24  
\<1.1.1.1\> attempting to start connection  
\<1.1.1.1\> using connection plugin network\_cli  
\<1.1.1.1\> local domain socket does not exist, starting it  
\<1.1.1.1\> control socket path is /home/user/.ansible/pc/d7df86492e  
\<1.1.1.1\> CUSTOM NETWORK\_CLI MODULE  
\<1.1.1.1\> \<1.1.1.1\> ESTABLISH PARAMIKO SSH CONNECTION FOR USER: user on PORT 22 TO 1.1.1.1  
\<1.1.1.1\> \<1.1.1.1\> ssh connection done, setting terminal  
\<1.1.1.1\> \<1.1.1.1\> loaded terminal plugin for network\_os fortios  
\<1.1.1.1\> \<1.1.1.1\> loaded cliconf plugin for network\_os fortios  
\<1.1.1.1\> \<1.1.1.1\> Response received, triggered ‘persistent\_buffer\_read\_timeout’ timer of 0.1 seconds  
\<1.1.1.1\> \<1.1.1.1\> firing event: on\_open\_shell()

\<1.1.1.1\> prompt detected on device DEVICENAME # \<\<\<\<====

The last line is printed during the call of “on\_open\_shell” in the “terminal\_plugins” (bellow, the source code), as you can see, I use “Display()”.

```auto
def on_open_shell(self):
    prompt = self._get_prompt()

    if re.search("Press 'a' to accept", prompt):
        self._exec_cli_command(b'a')
    if prompt:
        display.display('prompt detected on device ' + prompt)

```

And now I would like to have the same kind of log in the “debug mode (-vvvv)”, but from a cliconf\_plugin.

I dont want to like into a file.

I hope i’m clear 🙂 thanks for your help !
