Ignore:
Timestamp:
Jun 7, 2010 4:42:48 PM (11 years ago)
Author:
khunter
Message:

Begin Pyomo Logging implementation

Define a base line default for how to interact with our Logger.
Note the import necessary at the beginning of the module, and then
the module Logger set up with

Logger = logging.getLogger('Pyomo')

File:
1 edited

Legend:

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

    r2646 r2647  
    2121   print "ERROR: Pyomo requires Python 2.5.1 or newer"
    2222   sys.exit(1)
     23
    2324from os.path import abspath, dirname
     25import logging
    2426import os
     27
     28Logger = logging.getLogger('Pyomo')
     29
     30
    2531sys.path.insert(0, dirname(dirname(abspath(__file__))))
    2632sys.path.append(".")
     
    4955import coopr.pyomo.scripting.pyomo
    5056
     57class PyomoLogHandler ( logging.Handler ):
     58    def __init__ ( self, base, *args, **kwargs ):
     59        import logging  # why?  Shouldn't the import above be enough?
     60        logging.Handler.__init__(self, *args, **kwargs )
     61
     62        self.basepath = base
     63
     64    def emit(self, record):
     65        import sys   # why?  Isn't this imported above?
     66                     # Doesn't work w/o it though ... ?
     67
     68        level    = record.levelname
     69        filename = record.pathname  # file path
     70        lineno   = record.lineno
     71        function = record.funcName
     72        msg      = record.getMessage()
     73
     74        filename = filename.replace( self.basepath, '[coopr base]' )
     75
     76        print >> sys.stderr, '%(level)s: "%(fpath)s", %(lineno)d, %(caller)s\n\t%(msg)s\n' % \
     77            {
     78              'level'  : level,
     79              'fpath'  : filename,
     80              'lineno' : lineno,
     81              'caller' : function,
     82              'msg'    : msg,
     83            }
     84
     85
    5186try:
     87    Logger.addHandler( PyomoLogHandler(coopr_path) )
     88    Logger.setLevel( 1 )  # magic number to be updated via conf file soon.
     89    # 1 = lowest possible output.  i.e. everything
     90
    5291    coopr.pyomo.scripting.pyomo.run(args=sys.argv[1:])
    5392except SystemExit:
Note: See TracChangeset for help on using the changeset viewer.