Claudiu
Claudiu

Reputation: 229321

twistd.py log to both stdout and file

I'm using twistd.py to run my application as follows:

twistd -noy -l logfile.log tacfile.tac

The unfortunate thing with this is that all output now goes to the log file, which is better for debugging things in the past but worse for debugging things in the present. I want the best of both worlds... how can I make twistd log to stdout as well as to the file provided in the command line?

Upvotes: 2

Views: 1789

Answers (1)

Marek Kowalski
Marek Kowalski

Reputation: 1792

I'd try:

twistd -noy -l - tacfile.tac | tee logfile.log

"-l -" makes twistd log to stdout, tee saves it to the file and prints to stdout. On ubuntu tee comes from coreutils package.

<--- Edit below --->

If you want something only specific to twisted you can add the following code in the tac file:

from twisted.python import log, logfile

logFile = logfile.LogFile.fromFullPath('tacfile.log')
log.addObserver(log.FileLogObserver(logFile).emit)

and run twistd with "-l -"

Upvotes: 1

Related Questions