<div dir="ltr">I made that code into a program like this:<div><br></div><div style>### BEGIN</div><div><br></div><div><div>import logging</div><div><br></div><div>def configure_logging():</div><div><br></div><div>    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)8s %(message)s',</div>
<div>                        datefmt='%Y-%m-%d\t%H:%M:%s',</div><div>                        filename='/tmp/logfun.log', filemode='a')</div><div><br></div><div>    # define a Handler that writes INFO messages to sys.stderr</div>
<div>    console = logging.StreamHandler()</div><div>    console.setLevel(logging.INFO)</div><div><br></div><div>    # set format that is cleaber for console use</div><div>    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')</div>
<div><br></div><div>    # tell the handler to use this format</div><div>    console.setFormatter(formatter)</div><div><br></div><div>    # add the handler to the root logger</div><div>    logging.getLogger('').addHandler(console)</div>
<div><br></div><div>if __name__ == '__main__':</div><div><br></div><div>    configure_logging()</div><div><br></div><div>    logging.debug('a')</div><div>    <a href="http://logging.info">logging.info</a>('b')</div>
<div>    logging.warn('c')</div><div>    logging.error('d')</div><div>    logging.critical('e')</div></div><div><br></div><div style>### END</div><div style><br></div><div style>and when I run the program, I get INFO and greater messages to stderr:</div>
<div style><br></div><div style><div>$ python logfun.py </div><div>root        : INFO     b</div><div>root        : WARNING  c</div><div>root        : ERROR    d</div><div>root        : CRITICAL e</div><div><br></div><div style>
and I get this stuff in the log file:</div><div style><br></div><div style><div>$ cat /tmp/logfun.log </div><div>2013-03-12<span class="" style="white-space:pre">    </span>07:31:1363087862 root            DEBUG a</div><div>
2013-03-12<span class="" style="white-space:pre">     </span>07:31:1363087862 root             INFO b</div><div>2013-03-12<span class="" style="white-space:pre"> </span>07:31:1363087862 root          WARNING c</div><div>2013-03-12<span class="" style="white-space:pre"> </span>07:31:1363087862 root            ERROR d</div>
<div>2013-03-12<span class="" style="white-space:pre">  </span>07:31:1363087862 root         CRITICAL e</div><div><br></div><div style>In other words, your code works!  Maybe you should check permissions on the file you are writing to.</div>
<div style><br></div><div style>Matt</div><div><br></div></div></div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 8, 2013 at 9:07 AM,  <span dir="ltr"><<a href="mailto:gabor.a.halasz@gmail.com" target="_blank">gabor.a.halasz@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I would like to enable loggin in my script using the logging module that comes with Python 2.7.3.<br>
<br>
I have the following few lines setting up logging in my script, but for whatever reason  I don't seem to get any output to stdout  or to a file provided to the basicConfig method.<br>
<br>
Any ideas?<br>
<br>
# cinfiguring logging<br>
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)8s %(message)s',<br>
                    datefmt='%Y-%m-%d\t%H:%M:%s', filename=config["currentLoop"], filemode='a')<br>
# define a Handler that writes INFO messages to sys.stderr<br>
console = logging.StreamHandler()<br>
console.setLevel(logging.INFO)<br>
# set format that is cleaber for console use<br>
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')<br>
# tell the handler to use this format<br>
console.setFormatter(formatter)<br>
# add the handler to the root logger<br>
logging.getLogger('').addHandler(console)<br>
<span class="HOEnZb"><font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>W. Matthew Wilson<br><a href="mailto:matt@tplus1.com" target="_blank">matt@tplus1.com</a><br><a href="http://tplus1.com" target="_blank">http://tplus1.com</a><br>
<br>
</div>