I have a cronjob running a python script which I added a logging to, but since it's a daily job it is really annoying that I get daily emails of it's function, but I can't seem to find a setting, that will make it log only into the logfile.    
#!/usr/bin/python
import logging, logging.handlers
LOGFILENAME = "log.log" 
logging.basicConfig()
log = logging.getLogger("nameoflog")
log.setLevel(logging.DEBUG) 
handler = logging.handlers.WatchedFileHandler(LOGFILENAME)
handler.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter("%(asctime)-15s %(levelname)-8s %(name)s %(message)s")) 
log.addHandler(handler)
log.info("something happening")
How is it possible to make logging only write to a file and not to file and STDOUT?
The problem is that you call logging.basicConfig() which sets up logging to stdout. basicConfig is just a helper method used when you don't want to make more detailed logging calls. Since you setup the methods yourself, you should not call basicConfig.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With