Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28264

Logging handler: No output

From Florian Lindner <mailinglists@xgm.de>
Subject Logging handler: No output
Date 2012-09-02 13:12 +0200
Newsgroups comp.lang.python
Message-ID <mailman.81.1346584357.27098.python-list@python.org> (permalink)

Show all headers | View raw


Hello,

I have a class method that executes a subprocess. There are two loggers in the 
class, self.logger for general logging and proclog for process output (stdout 
& stderr) logging which should go to stdout and a file:    


def start_process(self, command, no_shlex=False, raise_excpt=True,
                  print_output = True, **kwargs):

    cmd = command if no_shlex else shlex.split(command)

    # Use an additional logger without formatting for process output. 
    proclog = logging.getLogger(self.config.tag)
    proclog.propagate = False # Process output should not propage to the main
                                logger
    logfile = self._logfilename()

    if logfile:
        proclog.addHandler(logging.FileHandler(logfile))
            
    if print_output:
        proclog.addHandler(logging.StreamHandler(sys.stdout))
    
    self.popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT, bufsize=0, **kwargs)
    while True:
        output = self.popen.stdout.readline().decode()
        if output == "" and self.popen.poll() != None:
            break
        proclog.info(output.rstrip("\n"))
                            
    ret_code = self.popen.returncode

    self.logger.debug("%s returned with %i", command, ret_code)


But neither the FileHandler nor the StreamHandler produce any actual output. 
The file is being created but stays empty. If I use a print output in the 
while loop it works, so output is catched and the applications stdout in 
working. But why the logger proclog catching nothing?

Thanks,

Florian

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Logging handler: No output Florian Lindner <mailinglists@xgm.de> - 2012-09-02 13:12 +0200
  Re: Logging handler: No output Paul Rubin <no.email@nospam.invalid> - 2012-09-02 04:30 -0700

csiph-web