Skip to content

Commit

Permalink
Better logging for environment
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Aug 15, 2018
1 parent ae2c8cf commit b8126af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
15 changes: 13 additions & 2 deletions src/configmanager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@
frozen = getattr(sys, "frozen", False)
RUNNING_FROM_FILE = not frozen

import gdal

if frozen:
os.environ['PATH'] += ";{}".format(os.path.join(srcpath, 'libs'))
os.environ['PATH'] += ";{}".format(srcpath)
os.environ['PATH'] = "{0};{1}".format(os.path.join(srcpath, 'libs'), srcpath)
os.environ["GDAL_DRIVER_PATH"] = os.path.join(srcpath, 'libs')
os.environ["GDAL_DATA"] = os.path.join(srcpath, 'libs', 'gdal')
os.environ['OGR_SQLITE_PRAGMA'] = "journal_mode=delete"

gdal.SetConfigOption("GDAL_DRIVER_PATH", os.environ['GDAL_DRIVER_PATH'])
gdal.SetConfigOption("GDAL_DATA", os.environ['GDAL_DATA'])
gdal.SetConfigOption('OGR_SQLITE_PRAGMA', os.environ['OGR_SQLITE_PRAGMA'])

from roam import utils, environ
config = {"loglevel": "DEBUG"}

utils.setup_logging(srcpath, config)

import roam.environ

Expand Down
26 changes: 18 additions & 8 deletions src/roam/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
The MainWindow object handles everything from there on in.
"""

import os
import sys


srcpath = os.path.dirname(os.path.realpath(sys.argv[0]))
sys.path.append(srcpath)

Expand All @@ -17,25 +15,37 @@
import gdal

if frozen:
os.environ['PATH'] += ";{}".format(os.path.join(srcpath, 'libs'))
os.environ['PATH'] += ";{}".format(srcpath)
os.environ['PATH'] = "{0};{1}".format(os.path.join(srcpath, 'libs'), srcpath)
os.environ["GDAL_DRIVER_PATH"] = os.path.join(srcpath, 'libs')
os.environ["GDAL_DATA"] = os.path.join(srcpath, 'libs', 'gdal')
os.environ['OGR_SQLITE_PRAGMA'] = "journal_mode=delete"

os.environ['OGR_SQLITE_PRAGMA'] = "journal_mode=delete"
gdal.SetConfigOption('OGR_SQLITE_PRAGMA', os.environ['OGR_SQLITE_PRAGMA'])
gdal.SetConfigOption("GDAL_DRIVER_PATH", os.environ['GDAL_DRIVER_PATH'])
gdal.SetConfigOption("GDAL_DATA", os.environ['GDAL_DATA'])

import roam.environ
from roam import utils, environ
config = {"loglevel": "DEBUG"}

utils.setup_logging(srcpath, config)

with roam.environ.setup(srcpath) as roamapp:
with environ.setup(srcpath) as roamapp:
import roam.config
import roam
import roam.mainwindow
import roam.utils

roam.utils.info("Runtime logging at: {}".format(roamapp.profileroot))
roam.utils.setup_logging(roamapp.profileroot, roam.config.settings)

roam.utils.debug("Environment:")
roam.utils.debug(os.environ["GDAL_DRIVER_PATH"])
roam.utils.debug(os.environ["GDAL_DATA"])
roam.utils.debug(os.environ["PATH"])

from qgis.core import QgsProviderRegistry
ecwsupport = 'ecw' in QgsProviderRegistry.instance().fileRasterFilters()
roam.utils.info("ECW Support: {0}".format(ecwsupport))

window = roam.mainwindow.MainWindow(roamapp)

roamapp.setActiveWindow(window)
Expand Down
2 changes: 1 addition & 1 deletion src/roam/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _setup(apppath=None, logo='', title='', **kwargs):
import roam.utils
if RUNNING_FROM_FILE:
roam.utils.debug("Running from file")
roam.utils.debug("App path {0}", apppath)
roam.utils.debug("App path {0}".format(apppath))
i18npath = os.path.join(apppath, "i18n")
if os.name == 'posix':
prefixpath = os.environ.get('QGIS_PREFIX_PATH', '/usr/')
Expand Down
10 changes: 7 additions & 3 deletions src/roam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from logging import handlers

from PyQt4 import uic
import gdal

logger = logging.getLogger("roam")

Expand All @@ -26,14 +27,14 @@ def setup_logging(approot, config=None):
:param approot: The folder to create the log folder in.
"""
if config is None:
config = {"loglevel": "INOF"}
config = {"loglevel": "INFO"}

try:
logpath = os.path.join(os.environ['ROAM_APPPATH'], 'log')
except KeyError:
logpath = os.path.join(approot, 'log')

print "Logging into:{}".format(logpath)
print "Logging into: {}".format(logpath)

if not os.path.exists(logpath):
os.makedirs(logpath)
Expand All @@ -57,16 +58,19 @@ def setup_logging(approot, config=None):
stream.setLevel(logging.DEBUG)
stream.setFormatter(console_formater)

logger.handlers = []
logger.addHandler(stream)
logger.addHandler(filehandler)
logger.setLevel(logging.DEBUG)

uic.uiparser.logger.setLevel(logging.INFO)
uic.properties.logger.setLevel(logging.INFO)
if levelname == "DEBUG":
import gdal
gdal.SetConfigOption("CPL_LOG", os.path.join(logpath, "gdallog.log"))
gdal.SetConfigOption("CPL_DEBUG", "ON")
else:
gdal.SetConfigOption("CPL_LOG", "")
gdal.SetConfigOption("CPL_DEBUG", "OFF")

faulthandler.enable(file=open(os.path.join(logpath, "crashlog.log"), 'w'))

Expand Down

0 comments on commit b8126af

Please sign in to comment.