Logging handler: No output

Discussion in 'Python' started by Florian Lindner, Sep 2, 2012.

  1. 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
    Florian Lindner, Sep 2, 2012
    #1
    1. Advertising

  2. Florian Lindner

    Paul Rubin Guest

    Florian Lindner <> 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.
    Paul Rubin, Sep 2, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    791
    John C. Bollinger
    Jan 27, 2006
  2. Replies:
    1
    Views:
    695
    Damien
    Feb 22, 2007
  3. Replies:
    0
    Views:
    352
  4. Gal Aviel
    Replies:
    1
    Views:
    457
    Gerard Flanagan
    Mar 4, 2008
  5. Vinay Sajip

    Re: Logging handler: No output

    Vinay Sajip, Sep 2, 2012, in forum: Python
    Replies:
    0
    Views:
    169
    Vinay Sajip
    Sep 2, 2012
Loading...

Share This Page