On Oct 28, 2015, at 4:10 AM, Markus Wanner <markus@bluegap.ch> wrote:


I'm trying to configure logging of my application depending on whether
or not the -y (--nodaemon) option of twistd is given. Actually very
similar to the default behavior, I would just like to switch to daily
log files. But it seems the application created has no access to the
config (used by underlying twistd and the ApplicationRunner).

What's the best way to switch to daily log files using twistd?

You have 3 options, pretty much:

  1. Submit a patch to Twisted that adds this option to twistd itself.  This is probably the most reasonable option, since you're asking for twistd to have a feature that it doesn't currently.  This is a great time to be submitting patches, too - we have two recipients of the Twisted fellowship right now available to do review work for the SFC, I have work time allotted to Twisted reviewing, and the review queue is consistently shorter than it's been in a long time.  So you are likely to get a quick response.
  2. Use the `-n´ option and run `twistd´ under a supervisor like systemd, consuming, writing, and rotating its logs without daemonizing, and handle log management outside of `twistd´.  This is probably the long-term direction that operations with Twisted will ultimately take, as you can see in some of the pontificating on <https://twistedmatrix.com/trac/ticket/5705>.
  3. Grovel around in unsupported global state like `sys.argv´ in your twistd plugin, and use private attributes to just change the structure of the objects internally.  I don't think this is a great idea and I probably won't help you with it ;).

The reason that state like this is not readily accessible to a twistd plugin is intentional, although we have long been paying the cost of making it difficult to configure without really realizing the benefit from this architecture, which is service composability.  For example, something like, "twistd -n web --path http + words --irc-port=6667 + mail --maildirdbmdomain=example.com=/tmp/example.com + auth ldap://corporate-active-directory" to give you IRC and web and mail all backed by the same authentication database.  If this is the case then no one plugin can really assert control over how logging is configured, so we have been trying to avoid doing a whole lot in the area of making it possible for your plugin to control the twistd environment it's started in.

If you really want to control every aspect of your deployment from your own code, you can always just import `twisted.scripts.twistd´ and build your own ServerOptions object that contains exactly what deployment options you want to use.

I hope this is helpful.  Thanks for using Twisted!