Skip to content

Commit 86bf100

Browse files
committed
Allow a way to disable log redirection through QgsMessageLog
By introducing `IS_WITHIN_QFC_WORKER` we are going to instruct `libqfieldsync` to not redirect logs to the `QgsMessageLog`, therefore avoiding repetitions such as: ``` 14:22:54.842 QGSMSGLOG INFO Layer "list_salutation" will use attribute "fid" as a primary key. 14:22:54.842 libqfieldsync INFO Layer "list_salutation" will use attribute "fid" as a primary key. ```
1 parent 043fe5a commit 86bf100

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

libqfieldsync/utils/logger.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import logging
2+
import os
23

34
from qgis.core import Qgis, QgsMessageLog
45
from qgis.PyQt.QtCore import QObject, pyqtSignal
56

7+
IS_WITHIN_QFC_WORKER = os.getenv("IS_WITHIN_QFC_WORKER", "0") == "1"
8+
69

710
def add_logging_level(level_name, levelno, method_name=None):
811
"""
@@ -90,7 +93,12 @@ def emit(self, record):
9093
msg = self.format(record)
9194
qgis_log_level = self._get_qgis_log_level(record)
9295

93-
QgsMessageLog.logMessage(msg, self.source, qgis_log_level)
96+
if IS_WITHIN_QFC_WORKER:
97+
# In QFieldCloud worker context, we avoid using `QgsMessageLog` as it causes way too much noise,
98+
# as the libqfieldsync logs are properly handled by the worker logging system.
99+
pass
100+
else:
101+
QgsMessageLog.logMessage(msg, self.source, qgis_log_level)
94102

95103
self.qgis_log_observer.emit(self.source, msg)
96104
except RecursionError: # See issue 36272

0 commit comments

Comments
 (0)