Python logs working on one pycharm and not on another
<p>I've created this python script to help me create log files while running my script and it works perfectly in my own machine. But for some reason the exact code does not work on other machines.
In my machine it shows the logs in pycharm console and also saves them in a file. In other machines it doesn't do anything except for creating a blank file.</p>

<p>What am I doing wrong?</p>

<pre><code>log = logging.getLogger('Logger Name')
try:
    logger_file_name = new_file_name()
    handler = logging.FileHandler(logger_file_name)
    formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
    handler.setFormatter(formatter)
    log.addHandler(handler)
    log.info(logger_file_name+ '  File will be used for Saving Logs')
    main()
except Exception as err:
    log.debug("An Error was found which was not caught")
    log.exception(err)
</code></pre>

<p>Try to explicitly set the logging level, for example:</p>

<pre><code>log.setLevel(logging.DEBUG) 
</code></pre>

<p>Otherwise you're relying on the default value which <em>might</em> be different on different python versions that may be installed on different machines. For example on 2.7.12 the default level is set to <code>WARNING</code> and the <code>log.info()</code> messages won't show up - just as you observed. </p>

<p>From the 2.7.12 logging doc's <a href="https://docs.python.org/2/howto/logging.html#a-simple-example" rel="nofollow">A simple example section</a>:</p>

<blockquote>
<pre><code>import logging
logging.warning('Watch out!')  # will print a message to the console
logging.info('I told you so')  # will not print anything
</code></pre>
  
  <p>If you type these lines into a script and run it, youâll see:</p>

<pre><code>WARNING:root:Watch out!
</code></pre>
  
  <p>printed out on the console. The <code>INFO</code> message doesnât appear because
  the default level is <code>WARNING</code>...</p>
</blockquote>

python logging pycharm