Hello everyone...<br /><br />My intention is to create a generic logging function I can use across scripts.  I have a few things I would like this function to be able to accomplish:<br /><br />1. log info and above to console<br />2. log debug and above to file<br />3. format the output for each differently<br />4. allow areas of a program to use a different &quot;logger&quot;, basically putting a different name in the event depending on which of my bad ideas broke the system<br />5. control log rotation within the script itself<br /><br />so far I have accomplished a lot of hair pulling...the following does some of the above:<br /><br />import logging<br />import sys<br /><br />LOG_FILENAME = &quot;./testing.log&quot;<br /><br />def set_logging(): <br />  # Set up a specific logger<br />  my_logger = logging.getLogger(sys.argv[0])<br />  # set up logging defaults<br />  logging.basicConfig(level=logging.DEBUG,<br />                    format=&#39;%(asctime)s %(name)-12s %(levelname)-8s %(message)s&#39;,<br />                    datefmt=&#39;%m-%d %H:%M:%S&#39;,<br />                    filename=LOG_FILENAME,<br />                    filemode=&#39;w&#39;)<br />  # define a Handler which writes INFO messages or higher to the sys.stderr<br />  console = logging.StreamHandler()<br />  console.setLevel(logging.INFO)<br />  # set a format which is simpler for console use<br />  formatter = logging.Formatter(&#39;%(levelname)-8s %(message)s&#39;)<br />  # tell the handler to use this format<br />  console.setFormatter(formatter)<br />  # add the handler to the root logger<br />  logging.getLogger(&#39;&#39;).addHandler(console)<br /><br />    <br />set_logging()<br />logging.debug(&quot;test_debug&quot;)<br />logging.info(&quot;testing_info&quot;)<br /><br />I also have a separate bit that can do the rotation:<br /><br />import glob<br />import logging<br />import logging.handlers<br />import sys<br /><br />LOG_FILENAME = &#39;./logging_rotateout&#39;<br /><br /># Set up a specific logger with our desired output level<br /><br />fullscriptname = os.path.split(sys.argv[0])<br />scriptname = fullscriptname[1]<br />log = logging.getLogger(scriptname)<br />log.setLevel(logging.DEBUG)<br /><br /># Add the log message handler to the logger<br />handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=20, backupCount=5)<br /><br />log.addHandler(handler)<br /><br />#log messages<br />log.debug(&quot;testing&quot;)<br />log.info(&quot;console&quot;)<br /><br /><br />I cannot for the life of me seem to combine these two functions, this seems odd to me, but I think I do not understand what logging.basicConfig does in the previous example.  If I try to add:<br /><br />  handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=20, backupCount=5)<br />  logging.getLogger(&#39;&#39;).addHandler(handler)<br /><br />to the first piece of code I get all kinds of errors, but mainly:<br /><br />AttributeError: &#39;module&#39; object has no attribute handlers<br /><br />I get this even though the line above it obviously adds the console handler.  I have tried many things, I wish I had documented better all of my attempts at syntax.<br /><br />Any help would be greatly appreciated.  Thanks.