Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Logging handler: No output

Reply
Thread Tools

Logging handler: No output

 
 
Florian Lindner
Guest
Posts: n/a
 
      09-02-2012
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.stdou t))

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


 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      09-02-2012
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Logging to a file and closing it again properly (logging module) Christoph Haas Python 1 06-14-2006 08:47 AM
Logging to a file and closing it again properly (logging module) Christoph Haas Python 0 06-12-2006 09:58 PM
logging buffered vs. logging history Christian Roos Cisco 4 02-05-2006 10:55 PM
java.util.logging, where to put logging.properties? janne Java 0 09-10-2004 10:18 AM
[java.util.logging] logging only to _one_ file Stefan Siegl Java 0 08-27-2003 12:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57