Commits

Aleš Erjavec committed fc917b3

Added logging to a file.

Comments (0)

Files changed (2)

Orange/OrangeCanvas/config.py

 """
 
 import os
+import sys
 import logging
 import cPickle as pickle
 import itertools
     return cachedir
 
 
+def log_dir():
+    """
+    Return the application log directory.
+    """
+    init()
+    if sys.platform == "darwin":
+        name = str(QCoreApplication.applicationName())
+        logdir = os.path.join(os.path.expanduser("~/Library/Logs"), name)
+    else:
+        logdir = data_dir()
+
+    if not os.path.exists(logdir):
+        os.makedirs(logdir)
+    return logdir
+
+
 def open_config():
     global rc
     app_dir = data_dir()

Orange/OrangeCanvas/main.py

     # and write to the old file descriptors)
     fix_win_pythonw_std_stream()
 
-    logging.basicConfig(level=levels[options.log_level])
+    # File handler should always be at least INFO level so we need
+    # the application root level to be at least at INFO.
+    root_level = min(levels[options.log_level], logging.INFO)
+    rootlogger = logging.getLogger(OrangeCanvas.__name__)
+    rootlogger.setLevel(root_level)
+
+    # Standard output stream handler at the requested level
+    stream_hander = logging.StreamHandler()
+    stream_hander.setLevel(level=levels[options.log_level])
+    rootlogger.addHandler(stream_hander)
 
     log.info("Starting 'Orange Canvas' application.")
 
     log.debug("Starting CanvasApplicaiton with argv = %r.", qt_argv)
     app = CanvasApplication(qt_argv)
 
+    # NOTE: config.init() must be called after the QApplication constructor
+    config.init()
+
+    file_handler = logging.FileHandler(
+        filename=os.path.join(config.log_dir(), "canvas.log"),
+        mode="w"
+    )
+
+    file_handler.setLevel(root_level)
+    rootlogger.addHandler(file_handler)
+
     # intercept any QFileOpenEvent requests until the main window is
     # fully initialized.
     # NOTE: The QApplication must have the executable ($0) and filename
 
     app.fileOpenRequest.connect(onrequest)
 
-    # Note: config.init must be called after the QApplication constructor
-    config.init()
     settings = QSettings()
 
     stylesheet = options.stylesheet
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.