Skip to content

Commit 6eeff16

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 6eeff16

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

libqfieldsync/utils/logger.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import os
12
import logging
23

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

67

8+
IS_WITHIN_QFC_WORKER = os.getenv("IS_WITHIN_QFC_WORKER", "0") == "1"
9+
10+
711
def add_logging_level(level_name, levelno, method_name=None):
812
"""
913
Comprehensively adds a new logging level to the `logging` module and the
@@ -90,7 +94,12 @@ def emit(self, record):
9094
msg = self.format(record)
9195
qgis_log_level = self._get_qgis_log_level(record)
9296

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

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

0 commit comments

Comments
 (0)