Changeset 3473


Ignore:
Timestamp:
Jan 15, 2011 6:22:48 AM (9 years ago)
Author:
khunter
Message:

Moving PyomoLogHandler? to pyutilib.misc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/scripts/pyomo

    r3213 r3473  
    5454    curr = os.path.dirname(curr)
    5555
    56 import coopr.pyomo.scripting.pyomo
    57 
    58 class PyomoLogHandler ( logging.Handler ):
    59     def __init__ ( self, base, *args, **kwargs ):
    60         import logging  # why?  Shouldn't the import above be enough?
    61         logging.Handler.__init__(self, *args, **kwargs )
    62 
    63         self.basepath = base
    64 
    65     def emit(self, record):
    66         import sys   # why?  Isn't this imported above?
    67                      # Doesn't work w/o it though ... ?
    68 
    69         level    = record.levelname
    70         filename = record.pathname  # file path
    71         lineno   = record.lineno
    72         msg      = record.getMessage()
    73         try:
    74             function = record.funcName
    75         except AttributeError:
    76             function = '(unknown)'
    77 
    78         filename = filename.replace( self.basepath, '[coopr base]' )
    79 
    80         sys.stderr.write('%(level)s: "%(fpath)s", %(lineno)d, '               \
    81                          '%(caller)s\n\t%(msg)s\n' % \
    82             {
    83               'level'  : level,
    84               'fpath'  : filename,
    85               'lineno' : lineno,
    86               'caller' : function,
    87               'msg'    : msg,
    88             }
    89         )
    90 
     56from coopr.pyomo.scripting.pyomo import run
     57from pyutilib.misc import LogHandler
    9158
    9259try:
    93     Logger.addHandler( PyomoLogHandler(coopr_path) )
     60    Logger.addHandler( LogHandler(coopr_path) )
    9461    Logger.setLevel( 30 )  # magic number to be updated via conf file soon.
    9562    # 1 = lowest possible output.  i.e. everything
    9663
    97     coopr.pyomo.scripting.pyomo.run(args=sys.argv[1:])
     64    run(args=sys.argv[1:])
    9865except SystemExit:
    9966    pass
Note: See TracChangeset for help on using the changeset viewer.