title: Python : Logging in module script to be called in another script
body: <p>I have around 15 different python scripts for an application development, among of which 10 includes logging for debugging purposes. Now there is a main script say "hutextract.py" which is to run with a filename as an argument. Previously the log file name was fixed "test.log". Now I want to create the logging file with the same name as the input filename (except the extension). My "hutextract.py" code, where "randpage" and "mandate" are other python scripts :</p>
  
  <pre><code>from randpage import genrand
  from mandatebase import formext
  ...# importing other scripts, functions
  import logging
  
  file_name=sys.argv[1]
  def return_log_name():
      return ".".join(file_name.split("/")[-1].split(".")[:-1]) + ".log"
  
  log_file_name = return_log_name()
  
  logging.basicConfig(filename=log_file_name, level=logging.DEBUG, format="%(asctime)s:%(levelname)s:%(message)s")
  </code></pre>
  
  <p>In randpage.py, mandatebase.py and other scripts, logging is also included there :</p>
  
  <pre><code>import logging
  from hutextract import return_log_name
  log_file_name = return_log_name()
  logging.basicConfig(filename=log_file_name, level=logging.DEBUG, format="%(asctime)s:%(levelname)s:%(message)s")
  </code></pre>
  
  <p>This creates an error which is obvious that when we try to run hutextract.py with argument which calls the other scripts (and their functions) which in return again summons return_log_name function from hutextract.py for logging purpose :</p>
  
  <pre><code>Traceback (most recent call last):
   File "hutextract.py", line 3, in &lt;module&gt;
      from randpage import genrand
   File "/home/src/randpage.py", line 3, in &lt;module&gt;
      from mandate_final import sigext
   File "/home/src/mandate_final.py", line 5, in &lt;module&gt;
      from hutextract import return_log_name
   File "/home/src/hutextract.py", line 3, in &lt;module&gt;
      from randpage import genrand
  ImportError: cannot import name 'genrand'
  </code></pre>
  
  <p>How to do the logging inside all the module scripts to save the log file with same name as the input filename given as an argument?</p>