Code

Ticket #6687: fastcgi-log-routing.diff

File fastcgi-log-routing.diff, 1.9 KB (added by tamas, 6 years ago)
Line 
1Index: django/core/servers/fastcgi.py
2===================================================================
3--- django/core/servers/fastcgi.py      (revision 7187)
4+++ django/core/servers/fastcgi.py      (working copy)
5@@ -38,6 +38,8 @@
6   daemonize=BOOL       whether to detach from terminal.
7   pidfile=FILE         write the spawned process-id to this file.
8   workdir=DIRECTORY    change to this directory when daemonizing
9+  outlog=FILE          write stdout to this file
10+  errlog=FILE          write stderr to this file
11 
12 Examples:
13   Run a "standard" fastcgi process on a file-descriptor
14@@ -69,6 +71,8 @@
15     'minspare': 2,
16     'maxchildren': 50,
17     'maxrequests': 0,
18+    'outlog': None,
19+    'errlog': None,
20 }
21 
22 def fastcgi_help(message=None):
23@@ -150,9 +154,15 @@
24         else:
25             return fastcgi_help("ERROR: Invalid option for daemonize parameter.")
26 
27+    daemon_kwargs = {}
28+    if options['outlog']:
29+        daemon_kwargs['out_log'] = options['outlog']
30+    if options['errlog']:
31+        daemon_kwargs['err_log'] = options['errlog']
32+
33     if daemonize:
34         from django.utils.daemonize import become_daemon
35-        become_daemon(our_home_dir=options["workdir"])
36+        become_daemon(our_home_dir=options["workdir"], **daemon_kwargs)
37 
38     if options["pidfile"]:
39         fp = open(options["pidfile"], "w")
40Index: django/utils/daemonize.py
41===================================================================
42--- django/utils/daemonize.py   (revision 7187)
43+++ django/utils/daemonize.py   (working copy)
44@@ -29,6 +29,8 @@
45         os.dup2(si.fileno(), sys.stdin.fileno())
46         os.dup2(so.fileno(), sys.stdout.fileno())
47         os.dup2(se.fileno(), sys.stderr.fileno())
48+        # set the custom file descriptors for python so they have correct buffering
49+        sys.stdout, sys.stderr = so, se
50 else:
51     def become_daemon(our_home_dir='.', out_log=None, err_log=None):
52         """