Changeset 10804 in hybrid


Ignore:
Timestamp:
May 12, 2012, 7:36:00 PM (13 years ago)
Author:
rick
Message:

De /tmp bevuilen is niet zo'n best plan. Gooi het maar naar de syslog, gaat het
altijd naar files die goed geroteerd zijn.

Related-To: nodefactory:ticket:161

Location:
branches/releng-9.0/nanobsd/files/usr/local/www
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/releng-9.0/nanobsd/files/usr/local/www/wlportal/index.cgi

    r10796 r10804  
    3030# Author  : Rick van der Zwet <info@rickvanderzwet.nl>
    3131# Licence : BSDLike http://wirelessleiden.nl/LICENSE
    32 import cgitb
    33 cgitb.enable(logdir="/tmp")
    34 
     32
     33class MultiTracebackHook:
     34  """A hook to replace sys.excepthook that shows tracebacks in syslog & HTML (using cgitb)"""
     35  def __init__(self, ident=None, enable=False):
     36    self.ident = ident
     37    if enable:
     38      self.enable()
     39
     40  def __call__(self, etype, evalue, etb):
     41    self.handle((etype, evalue, etb))
     42
     43  def handle(self, info=None):
     44    import cgitb
     45    import os
     46    import sys
     47    import syslog
     48    import traceback
     49    info = info or sys.exc_info()
     50    tb = traceback.format_exception(*info)
     51    if self.ident:
     52      syslog.openlog(self.ident)
     53    prefix = '[%i]' % os.getpid()
     54    for line in tb:
     55      syslog.syslog(line)
     56    cgitb.handler(info)
     57
     58  def enable(self):
     59    import sys
     60    sys.excepthook = self
     61
     62MultiTracebackHook(enable=True)
    3563
    3664import os
  • branches/releng-9.0/nanobsd/files/usr/local/www/wlweb/index.cgi

    r10727 r10804  
    66# Rick van der Zwet <info@rickvanderzwet.nl>
    77# Richard van Mansom <richardvm@wirelessleiden.nl>, stripped the webserver
    8 import cgitb
    9 cgitb.enable(logdir="/tmp")
     8
     9class MultiTracebackHook:
     10  """A hook to replace sys.excepthook that shows tracebacks in syslog & HTML (using cgitb)"""
     11  def __init__(self, ident=None, enable=False):
     12    self.ident = ident
     13    if enable:
     14      self.enable()
     15
     16  def __call__(self, etype, evalue, etb):
     17    self.handle((etype, evalue, etb))
     18
     19  def handle(self, info=None):
     20    import cgitb
     21    import os
     22    import sys
     23    import syslog
     24    import traceback
     25    info = info or sys.exc_info()
     26    tb = traceback.format_exception(*info)
     27    if self.ident:
     28      syslog.openlog(self.ident)
     29    prefix = '[%i]' % os.getpid()
     30    for line in tb:
     31      syslog.syslog(line)
     32    cgitb.handler(info)
     33
     34  def enable(self):
     35    import sys
     36    sys.excepthook = self
     37
     38MultiTracebackHook(enable=True)
    1039
    1140from subprocess import *
Note: See TracChangeset for help on using the changeset viewer.