# Suggested way to log to a file?

**URL:** <https://discourse.mitmproxy.org/t/suggested-way-to-log-to-a-file/835>\
**Category:** help\
**Created:** [January 29, 2018, 8:48pm UTC](https://discourse.mitmproxy.org/t/suggested-way-to-log-to-a-file/835 "2018-01-29T20:48:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ironhokie](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@ironhokie](https://discourse.mitmproxy.org/u/ironhokie)\
**Post date:** [January 29, 2018, 8:48pm UTC](https://discourse.mitmproxy.org/t/suggested-way-to-log-to-a-file/835/1 "2018-01-29T20:48:46Z")

</div>

I’m leaving mitmdump running for a long time with custom input scripts. I’d like logs (created by ctx.log.\*(message)) to go to a file, where it looks like ctx.log goes to STDOUT. What’s the suggested way to achieve this?

I’m reluctant to redirect all stdout,stderr to a file, because mitmdump generates a lot of messages I’d prefer not to see in this log (e.g., clientconnect & clientdisconnect messages).

Thanks!

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [January 30, 2018, 6:11pm UTC](https://discourse.mitmproxy.org/t/suggested-way-to-log-to-a-file/835/2 "2018-01-30T18:11:37Z")

</div>

Hi,

You can write your own addon to log to file. In fact mitmproxy’s logging to stdout is an addon itself: [https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/termlog.py](https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/termlog.py).
