-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,10 @@ | |
__email__ = '[email protected]' | ||
|
||
import functools | ||
import inspect | ||
import time | ||
import traceback | ||
|
||
from contextlib import contextmanager | ||
from pathlib import Path | ||
|
||
from qgis.core import Qgis, QgsMessageLog | ||
|
||
|
@@ -19,27 +17,24 @@ class Logger: | |
|
||
@staticmethod | ||
def info(message: str): | ||
QgsMessageLog.logMessage(PLUGIN + ' : ' + message, PLUGIN, Qgis.Info) | ||
QgsMessageLog.logMessage(str(message), PLUGIN, Qgis.Info) | ||
|
||
@staticmethod | ||
def warning(message: str): | ||
QgsMessageLog.logMessage(PLUGIN + ' : ' + message, PLUGIN, Qgis.Warning) | ||
QgsMessageLog.logMessage(str(message), PLUGIN, Qgis.Warning) | ||
|
||
@staticmethod | ||
def critical(message: str): | ||
QgsMessageLog.logMessage(PLUGIN + ' : ' + message, PLUGIN, Qgis.Critical) | ||
QgsMessageLog.logMessage(str(message), PLUGIN, Qgis.Critical) | ||
|
||
@staticmethod | ||
def log_exception(e: BaseException): | ||
""" Log a Python exception. """ | ||
QgsMessageLog.logMessage( | ||
"Exception: {plugin}\n{e}\n{traceback}".format( | ||
plugin=PLUGIN, | ||
Logger.critical( | ||
"Critical exception:\n{e}\n{traceback}".format( | ||
e=e, | ||
traceback=traceback.format_exc() | ||
), | ||
PLUGIN, | ||
Qgis.Critical | ||
) | ||
) | ||
|
||
|
||
|
@@ -69,9 +64,7 @@ def log_function_core(*args, **kwargs): | |
start = time.time() | ||
value = func(*args, **kwargs) | ||
end = time.time() | ||
Logger.info( | ||
"{}.{}.{} ran in {}s".format( | ||
PLUGIN, Path(inspect.stack()[1].filename).stem, func.__name__, round(end - start, 2))) | ||
Logger.info("{} ran in {}s".format(func.__name__, round(end - start, 2))) | ||
return value | ||
|
||
return log_function_core |