Python logging daemon destroys file handle
问题 My script logs to a file just fine until I try to fork it into the background at which point the file handle is closed, even if I use filesPreserve. How can I improve this in a lightweight fashion so that my logger runs in the background? #!/usr/bin/env python from socket import * import sys, time, logging import daemon context = daemon.DaemonContext() logger = logging.getLogger('audit') hdlr = logging.FileHandler('/mnt/audit.log') formatter = logging.Formatter('%(asctime)s %(message)s') hdlr