klein icon indicating copy to clipboard operation
klein copied to clipboard

Unwanted logs

Open sxeran opened this issue 8 years ago • 1 comments

I am not using twisted logs infrastructure. Also, I am using a json formatter and not a concat formatter.

In Klein run method there is this block of code:

if logFile is None:
    logFile = sys.stdout

log.startLogging(logFile)

What happens is that I get each log twice in my stdout, once with a concat formatter. I would like an option to tell Klein not to startLogging at all.

Thanks ahead for any help :)

sxeran avatar Jan 17 '17 14:01 sxeran

At the moment there isn't a way to "turn off" logging. However, you do have a few options:

  • Provide a file object or point to /dev/null for logFile (easiest)
# ...
my_log = open('my_log.log', 'ab')
router.run('0.0.0.0', 8080, my_log)
  • Use the "Twisted way" and don't start Twisted logs
from klein import Klein
from twisted.web.server import Site
from twisted.internet import reactor, endpoints

router = Klein()
# ...
web_server = endpoints.serverFromString(reactor, "tcp:8080")
web_server.listen(Site(router.resource()))
  • Subclass Klein and override run without log.startLogging(logFile)

notoriousno avatar Jan 18 '17 02:01 notoriousno