Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning Python script as upstart service shows different time output
    primarykey
    data
    text
    <p>I have a python script that is essentially a small socket server that does some simple network tasks for me, and I started running it as an upstart service to keep track of it and manage whether or not it was running. To log information, I am using Python's built in logging module. When running as an Upstart service, I noticed a small problem: All of the time calls come out in GMT. When running it on its own(either <code>./scriptname.py</code> or <code>python scriptname.py</code>) it uses local time, and Python is aware of the local time. The system time is set correctly, and I only see this behavior when running as an upstart service. Does anyone know why this would happen and how I could fix it?</p> <p>EDIT: Relevant code: I have a helper class, conveniently called helper, that contains some oft used functions (I know it needs to be better organized, but it was thrown together fairly quickly). Most notably this function that I use to set up my logger:</p> <pre><code>class helper: log_format = '%(asctime)-25s %(name)-25s %(levelname)-12s %(message)s' @staticmethod def createLogger(name): rotatingFile = logging.handlers.RotatingFileHandler('/var/log/myLog.log', maxBytes=1048576, backupCount=5) rotatingFile.setLevel(logging.DEBUG) formatter = logging.Formatter(helper.log_format) formatter.time = localtime() rotatingFile.setFormatter(formatter) log = logging.getLogger(name) log.setLevel(logging.DEBUG) logging.basicConfig(format=helper.log_format, level=logging.DEBUG) if not log.handlers: log.addHandler(rotatingFile) return log </code></pre> <p>And it gets used like this in one of my classes:</p> <pre><code>class MyClass: def __init__(self): self._log = helper.createLogger('LogName') self._log.info('Some relevant info') _log = None </code></pre> <p>It's all pretty straightforward use of the python internal logging tools. I added the <code>formatter.time = localtime()</code> after I started noticing this problem, but before I realized that it only happened when run as a service. It didn't help.</p> <p>Here is my (very basic) upstart config that I got from a tutorial:</p> <pre><code>description "Blah blah" author "My Name &lt;My Email&gt;" start on runlevel [234] stop on runlevel [0156] exec /path/to/script.py respawn </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload