Logging handler: No output
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
logfile = self._logfilename()
self.popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, bufsize=0, **kwargs)
output = self.popen.stdout.readline().decode()
if output == "" and self.popen.poll() != None:
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?
Re: Logging handler: No output
Florian Lindner <firstname.lastname@example.org> writes:
> 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?
I don't see you setting the log level anyplace in that sample, and
you are logging at INFO and DEBUG levels. By default, only WARNING
and above only actually produce output. If you want INFO and DEBUG
to log, you have to request it.
|All times are GMT. The time now is 03:24 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.