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


Groups > comp.lang.python > #28264 > unrolled thread

Logging handler: No output

Started byFlorian Lindner <mailinglists@xgm.de>
First post2012-09-02 13:12 +0200
Last post2012-09-02 04:30 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#28264 — Logging handler: No output

FromFlorian Lindner <mailinglists@xgm.de>
Date2012-09-02 13:12 +0200
SubjectLogging handler: No output
Message-ID<mailman.81.1346584357.27098.python-list@python.org>
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

[toc] | [next] | [standalone]


#28266

FromPaul Rubin <no.email@nospam.invalid>
Date2012-09-02 04:30 -0700
Message-ID<7xzk58fyqn.fsf@ruckus.brouhaha.com>
In reply to#28264
Florian Lindner <mailinglists@xgm.de> 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web