~ubuntu-branches/ubuntu/maverick/coherence/maverick

« back to all changes in this revision

Viewing changes to coherence/extern/log/log.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2010-01-02 10:57:15 UTC
  • mfrom: (1.1.7 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100102105715-sghzl2nw4lr5b1ob
Tags: 0.6.6.2-1
*  New  upstream release, summary of changes:
    - adding all necessary files to MANIFEST.in, to compensate for the
      gone 'auto-include-all-files-under-version-control' setuptools
      feature.
    - rearranging genre and genres attribute in DIDLLite - thx Caleb  
    - fix face_path typo, fixes #275.   

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
    global _log_handlers_limited
165
165
 
166
166
    (_DEBUG,
167
 
     _categories,
 
167
     categories,
168
168
     _log_handlers,
169
169
     _log_handlers_limited) = state
170
170
 
171
 
    for category in _categories:
 
171
    for category in categories:
172
172
        registerCategory(category)
173
173
 
174
174
 
273
273
    for items in kwargs.items():
274
274
        debugArgs.extend(items)
275
275
    debugArgs.extend(endArgs)
276
 
    format = startFormat \
 
276
    debugFormat = startFormat \
277
277
              + ', '.join(('%s', ) * len(args)) \
278
278
              + (kwargs and ', ' or '') \
279
279
              + ', '.join(('%s=%r', ) * len(kwargs)) \
280
280
              + endFormat
281
 
    return format, debugArgs
 
281
    return debugFormat, debugArgs
282
282
 
283
283
 
284
284
def doLog(level, object, category, format, args, where=-1,
421
421
    safeprintf(sys.stderr, '%s [%5d] %-32s %-17s %-15s ',
422
422
               getFormattedLevelName(level), os.getpid(), o, category,
423
423
               time.strftime("%b %d %H:%M:%S"))
424
 
    safeprintf(sys.stderr, '%-4s %s %s\n', "", message, where)
 
424
 
 
425
    try:
 
426
        safeprintf(sys.stderr, '%-4s %s %s\n', "", message, where)
 
427
    except UnicodeEncodeError:
 
428
        # this can happen if message is a unicode object, convert it back into
 
429
        # a string using the UTF-8 encoding
 
430
        message = message.encode('UTF-8')
 
431
        safeprintf(sys.stderr, '%-4s %s %s\n', "", message, where)
425
432
 
426
433
    sys.stderr.flush()
427
434
 
691
698
            info('log', "Calling old SIGHUP hander")
692
699
            _old_hup_handler(signum, frame)
693
700
 
694
 
    debug('log', 'installing SIGHUP handler')
695
 
    import signal
696
 
    handler = signal.signal(signal.SIGHUP, sighup)
697
 
    if handler == signal.SIG_DFL or handler == signal.SIG_IGN:
698
 
        _old_hup_handler = None
 
701
    try:
 
702
        import signal
 
703
    except ImportError:
 
704
        debug('log', 'POSIX signals not supported, unable to install'
 
705
              ' SIGHUP handler')
699
706
    else:
700
 
        _old_hup_handler = handler
 
707
        debug('log', 'installing SIGHUP handler')
 
708
        handler = signal.signal(signal.SIGHUP, sighup)
 
709
        if handler == signal.SIG_DFL or handler == signal.SIG_IGN:
 
710
            _old_hup_handler = None
 
711
        else:
 
712
            _old_hup_handler = handler
701
713
 
702
714
 
703
715
# base class for loggable objects
725
737
        log.DEBUG, log.ERROR or log.LOG.
726
738
        @type  level: int
727
739
        """
728
 
        logHandlers = {WARN: self.warning,
729
 
                       INFO: self.info,
730
 
                       DEBUG: self.debug,
731
 
                       ERROR: self.error,
732
 
                       LOG: self.log}
733
 
        logHandler = logHandlers.get(level)
734
 
        if logHandler:
735
 
            logHandler('%s', marker)
 
740
        # errorObject specifically raises, so treat it specially
 
741
        if level == ERROR:
 
742
            self.error('%s', marker)
 
743
 
 
744
        doLog(level, self.logObjectName(), self.logCategory, '%s', marker)
736
745
 
737
746
    def error(self, *args):
738
747
        """Log an error.  By default this will also raise an exception."""
950
959
        else:
951
960
            text = ' '.join(map(str, edm))
952
961
 
953
 
        fmtDict = {'system': eventDict['system'],
954
 
                   'text': text.replace("\n", "\n\t")}
955
 
        msgStr = " [%(system)s] %(text)s\n" % fmtDict
 
962
        msgStr = " [%(system)s] %(text)s\n" % {
 
963
                'system': eventDict['system'],
 
964
                'text': text.replace("\n", "\n\t")}
956
965
        # because msgstr can contain %, as in a backtrace, make sure we
957
966
        # don't try to splice it
958
967
        method('twisted', msgStr)