Add logging
This commit is contained in:
parent
2b84768902
commit
5efa56c5bb
@ -1,10 +1,36 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
from PyQt5.QtWidgets import QWidget, QApplication
|
from PyQt5.QtWidgets import QWidget, QApplication
|
||||||
from qutebrowser.widgets.mainwindow import MainWindow
|
from qutebrowser.widgets.mainwindow import MainWindow
|
||||||
from qutebrowser.commands.keys import KeyParser
|
from qutebrowser.commands.keys import KeyParser
|
||||||
import qutebrowser.commands.utils as cmdutils
|
import qutebrowser.commands.utils as cmdutils
|
||||||
|
|
||||||
|
def parseopts():
|
||||||
|
parser = argparse.ArgumentParser("usage: %(prog)s [options]")
|
||||||
|
parser.add_argument('-l', '--log', dest='loglevel', help='Set loglevel',
|
||||||
|
default=0)
|
||||||
|
args = parser.parse_args()
|
||||||
|
return args
|
||||||
|
|
||||||
|
def initlog(args):
|
||||||
|
""" Initialisation of the log """
|
||||||
|
if (args.loglevel):
|
||||||
|
loglevel = args.loglevel
|
||||||
|
else:
|
||||||
|
loglevel = 'info'
|
||||||
|
numeric_level = getattr(logging, loglevel.upper(), None)
|
||||||
|
if not isinstance(numeric_level, int):
|
||||||
|
raise ValueError('Invalid log level: %s' % loglevel)
|
||||||
|
logging.basicConfig(
|
||||||
|
level=numeric_level,
|
||||||
|
format='%(asctime)s [%(levelname)s] [%(module)s:%(funcName)s:%(lineno)s] %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
args = parseopts()
|
||||||
|
initlog(args)
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
mw = MainWindow()
|
mw = MainWindow()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from PyQt5.QtCore import QObject, Qt, pyqtSignal
|
from PyQt5.QtCore import QObject, Qt, pyqtSignal
|
||||||
from PyQt5.QtWidgets import QShortcut
|
from PyQt5.QtWidgets import QShortcut
|
||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QKeySequence
|
||||||
|
import logging
|
||||||
|
|
||||||
class KeyParser(QObject):
|
class KeyParser(QObject):
|
||||||
keyparent = None
|
keyparent = None
|
||||||
@ -18,7 +19,7 @@ class KeyParser(QObject):
|
|||||||
def from_cmd_dict(self, d):
|
def from_cmd_dict(self, d):
|
||||||
for cmd in d.values():
|
for cmd in d.values():
|
||||||
if cmd.key is not None:
|
if cmd.key is not None:
|
||||||
print('reg: {} -> {}'.format(cmd.name, cmd.key))
|
logging.debug('registered: {} -> {}'.format(cmd.name, cmd.key))
|
||||||
sc = QShortcut(self.keyparent)
|
sc = QShortcut(self.keyparent)
|
||||||
sc.setKey(QKeySequence(cmd.key))
|
sc.setKey(QKeySequence(cmd.key))
|
||||||
sc.setContext(Qt.WidgetWithChildrenShortcut)
|
sc.setContext(Qt.WidgetWithChildrenShortcut)
|
||||||
|
Loading…
Reference in New Issue
Block a user