Changeset 11702:fc917b3c9a15 in orange


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

Added logging to a file.

Location:
Orange/OrangeCanvas
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/config.py

    r11532 r11702  
    55 
    66import os 
     7import sys 
    78import logging 
    89import cPickle as pickle 
     
    170171        os.makedirs(cachedir) 
    171172    return cachedir 
     173 
     174 
     175def log_dir(): 
     176    """ 
     177    Return the application log directory. 
     178    """ 
     179    init() 
     180    if sys.platform == "darwin": 
     181        name = str(QCoreApplication.applicationName()) 
     182        logdir = os.path.join(os.path.expanduser("~/Library/Logs"), name) 
     183    else: 
     184        logdir = data_dir() 
     185 
     186    if not os.path.exists(logdir): 
     187        os.makedirs(logdir) 
     188    return logdir 
    172189 
    173190 
  • 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.