Log with timestamp

Hello,
I want to write all log to standard error and standard output with a timestamp prefix: where I have to modify?

Thanks in advance.

Hi,

You can either write our own script, pipe mitmdump’s output through some unix tool that adds timestamps, or modify https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/dumper.py. :slight_smile:

Thank you for your response.
I try to modify the class you linked insert the command
text = datetime.today().isoformat() + ' ' + text;
before the line
click.secho(text, file=self.outfp, **style)
in the method echo
but with mitmdump I don’t see any difference in the standard output.
What can I do?

I came back to this point and I see this log:

Proxy server listening at http://0.0.0.0:8888
192.168.3.128:50011: clientconnect
2018-01-25T12:21:13 192.168.3.128:50011: GET http://www.google.it/
2018-01-25T12:21:13 << 302 Found 230b
192.168.3.128:50012: clientconnect
192.168.3.128:50013: clientconnect
192.168.3.128:50014: clientconnect
192.168.3.128:50015: clientconnect
2018-01-25T12:21:13 192.168.3.128:50014: GET Google
2018-01-25T12:21:13 << 200 OK 64.09k

How can I put a timestamp before every line? Can I put also the log level (ERROR, WARN, INFO, …)?

Thanks

Oh, it looks like you also need to adjust https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/termlog.py. :slight_smile:

Perfect!

I added

        #add timestamp and log level as message prefix
        ts = datetime.utcnow().isoformat("T", "seconds")
        level = "{:5s}".format(e.level.upper())
        e.msg = ts + " " + level + " " + e.msg

before the click.secho calling (from datetime import datetime).

Here the result:

2018-01-25T13:30:07 INFO Proxy server listening at http://0.0.0.0:8888
2018-01-25T13:30:13 INFO 192.168.3.128:53349: clientconnect
2018-01-25T13:30:13 192.168.3.128:53349: GET https://www.google.it
2018-01-25T13:30:13 << 200 OK 8.94k

1 Like

Thanks for this tip. I modified

  • /home/pi/.local/lib/python3.5/site-packages/mitmproxy/addons/termlog.py
    on my raspbian linux

How do I regenerate the pyc file?

  • /home/pi/.local/lib/python3.5/site-packages/mitmproxy/addons/pycache/termlog.cpython-35.pyc