title: Changing time format inside twisted matrix log
body: <p>how may i change the time format of the logging system used in TwistedMatrix ?</p>
  
  <p>i have noticed from
  <a href="http://twistedmatrix.com/trac/browser/tags/releases/twisted-11.0.0/twisted/python/log.py#L389" rel="nofollow">http://twistedmatrix.com/trac/browser/tags/releases/twisted-11.0.0/twisted/python/log.py#L389</a>
  that one should be allowed to change timeFormat, but it does not work
  for me, here is my full test program that i execute <code>python myscript.py</code></p>
  
  <pre><code>from twisted.internet import endpoints, reactor
  
  from twisted.python import log
  from twisted.application.service import Application
  from twisted.python.log import ILogObserver, FileLogObserver
  from twisted.python.logfile import DailyLogFile
  
  #[... here my definition of a ProxyFactory()...]
  
  application = Application("myapp")
  logfile = DailyLogFile("my.log", './')
  flo = FileLogObserver(logfile)
  flo.timeFormat = "%Y-%m-%d %H:%M:%S,%f%z"
  application.setComponent(ILogObserver, flo.emit)
  
  log.startLogging(logfile)
  log.msg("this is a test")
  
  endpoint = endpoints.serverFromString(reactor, portstr)
  d = endpoint.listen(ProxyFactory())
  d.addErrback(shutdown, reactor)
  reactor.run()
  </code></pre>
  
  <p>do not get the expected: "%Y-%m-%d %H:%M:%S,%f%z" (milliseconds)</p>
  
  <pre><code>2013-06-12 17:08:07+0200 [-] Log opened.
  2013-06-12 17:08:12+0200 [-] this is a test
  </code></pre>
  
  <p>what am i missing?</p>
  
  <p>also:</p>
  
  <ul>
  <li>how must i proceed to change this time format, when i do not need file
  logging but only stderr printing?</li>
  </ul>
  
  <p>( other reference: <a href="http://twistedmatrix.com/trac/ticket/3513" rel="nofollow">http://twistedmatrix.com/trac/ticket/3513</a> )</p>
  
  <p>EDIT: i tried to rephrase my two questions. </p>
  
  <p>so from the answer posted by JeanPaul, i understand that i was mixing things and classic python file with another <code>tac</code> file (that i do not know before reading JeanPaul). BTW i tried this one below and do not still get the milliseconds i need:</p>
  
  <p>(this time i am launching <code>twistd -noy my.tac</code>)</p>
  
  <pre><code>from twisted.application.service import Application
  from twisted.python.log import ILogObserver, FileLogObserver
  from twisted.python.logfile import DailyLogFile
  
  application = Application("myapp")
  logfile = DailyLogFile("my.log", "./")
  flo = FileLogObserver(logfile)
  flo.timeFormat = "%Y-%m-%d %H:%M:%S,%f %z"
  application.setComponent(ILogObserver, flo.emit)
  </code></pre>
  
  <p>and get:</p>
  
  <pre><code>2013-06-13 17:23:23,%f+0000 [-] Log opened.
  2013-06-13 17:23:23,%f+0000 [-] using set_wakeup_fd
  2013-06-13 17:23:23,%f+0000 [-] twistd 12.0.0 (/usr/bin/python 2.7.3) starting up.
  2013-06-13 17:23:23,%f+0000 [-] reactor class: twisted.internet.pollreactor.PollReactor.
  2013-06-13 17:23:30,%f+0000 [-] Received SIGINT, shutting down.
  2013-06-13 17:23:30,%f+0000 [-] Main loop terminated.
  2013-06-13 17:23:30,%f+0000 [-] Server Shut Down.
  </code></pre>
  
  <p>as you can see if i mimic what is done @ <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/python/log.py#L351" rel="nofollow">http://twistedmatrix.com/trac/browser/trunk/twisted/python/log.py#L351</a> , see line 367, python and time give me this milliseconds. notice also the %Z is wrong it should be +0200, but i will be able to live with that while i need milliseconds...</p>
  
  <pre><code>Python 2.7.3 (default, Jan  2 2013, 13:56:14)
  [GCC 4.7.2] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import datetime
  &gt;&gt;&gt; datetime.datetime.now().strftime("%H:%M:%S.%f")
  '17:28:06.566135'
  &gt;&gt;&gt; import time
  &gt;&gt;&gt; when = time.time()
  &gt;&gt;&gt; import datetime
  &gt;&gt;&gt; datetime.datetime.fromtimestamp(when).strftime("%Y-%m-%d %H:%M:%S,%f%z")
  '2013-06-13 17:33:20,535350'
  &gt;&gt;&gt; import twisted
  &gt;&gt;&gt; twisted.version
  Version('twisted', 12, 0, 0)
  </code></pre>