Ignore:
Timestamp:
09/13/13 17:26:19 (7 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added logging to a file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/main.py

    r11676 r11702  
    110110    fix_win_pythonw_std_stream() 
    111111 
    112     logging.basicConfig(level=levels[options.log_level]) 
     112    # File handler should always be at least INFO level so we need 
     113    # the application root level to be at least at INFO. 
     114    root_level = min(levels[options.log_level], logging.INFO) 
     115    rootlogger = logging.getLogger(OrangeCanvas.__name__) 
     116    rootlogger.setLevel(root_level) 
     117 
     118    # Standard output stream handler at the requested level 
     119    stream_hander = logging.StreamHandler() 
     120    stream_hander.setLevel(level=levels[options.log_level]) 
     121    rootlogger.addHandler(stream_hander) 
    113122 
    114123    log.info("Starting 'Orange Canvas' application.") 
     
    126135    log.debug("Starting CanvasApplicaiton with argv = %r.", qt_argv) 
    127136    app = CanvasApplication(qt_argv) 
     137 
     138    # NOTE: config.init() must be called after the QApplication constructor 
     139    config.init() 
     140 
     141    file_handler = logging.FileHandler( 
     142        filename=os.path.join(config.log_dir(), "canvas.log"), 
     143        mode="w" 
     144    ) 
     145 
     146    file_handler.setLevel(root_level) 
     147    rootlogger.addHandler(file_handler) 
    128148 
    129149    # intercept any QFileOpenEvent requests until the main window is 
     
    142162    app.fileOpenRequest.connect(onrequest) 
    143163 
    144     # Note: config.init must be called after the QApplication constructor 
    145     config.init() 
    146164    settings = QSettings() 
    147165 
Note: See TracChangeset for help on using the changeset viewer.