title: Best practice to write logs in /var/log from a python script?
body: <p>I want to write some log informations from a python's main script into a file in /var/log.</p>
  
  <p>When I call <code>logger.info("Starting")</code>, I get a PermissionError on the file, what is quite normal since files in /var/log belong to root and my program is not run as root.</p>
  
  <p>I could of course set <code>/var/log/my.log</code>'s rights in order to let myapp write into it. (Set the same group for instance). But it doesn't look like a good practice to me: what if I install myapp on another computer? Should I then change the rights on the log file during the install process? Or is there another more generic way to do that? (Like a generic way to send the logs to "the system"? By generic I mean also portable, what would work on linux, freebsd etc.)</p>
  
  <p>Though I'm not sure it's relevant, for information, here are some portions of my code:</p>
  
  <p>Main script:</p>
  
  <pre><code>import logging, logging.config
  
  from lib import settings
  settings.init()
  
  logging.config.fileConfig(settings.logging_conf_file)
  logger = logging.getLogger(__name__)
  </code></pre>
  
  <p>The handler matching <code>settings.logging_conf_file</code>, in the logging config file:</p>
  
  <pre><code>[handler_mainHandler]
  class=FileHandler
  level=INFO
  formatter=defaultFormatter
  filemode=w
  args=('/var/log/myapp.log',)
  </code></pre>