klein
klein copied to clipboard
Unwanted logs
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 :)
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
forlogFile
(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 overriderun
withoutlog.startLogging(logFile)