Log with timestamp


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

Thanks in advance.



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 clientconnect
2018-01-25T12:21:13 GET http://www.google.it/
2018-01-25T12:21:13 << 302 Found 230b clientconnect clientconnect clientconnect clientconnect
2018-01-25T12:21:13 GET https://www.google.it/?gws_rd=ssl
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, …)?



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



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
2018-01-25T13:30:13 INFO clientconnect
2018-01-25T13:30:13 GET https://www.google.it
2018-01-25T13:30:13 << 200 OK 8.94k