F
Florian Lindner
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
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