1- #! python3
1+ #!/usr/bin/env python3
2+ """Logging helpers that forward Python logging into QGIS messaging systems.
3+
4+ This module provides a convenience `PlgLogger` for emitting user-facing
5+ messages to the QGIS message log and message bar, and `PlgLoggerHandler` that
6+ bridges Python's `logging` into the plugin's logging facilities.
7+ """
28
39# standard library
410import logging
@@ -132,21 +138,24 @@ def log(
132138
133139
134140class PlgLoggerHandler (logging .Handler ):
135- """
136- Standard logging.Handler that forwards logs to PlgLogger.log().
141+ """Handler that forwards Python log records to the plugin logger.
142+
143+ The handler calls the provided `plg_logger_class.log()` static method to
144+ forward formatted log messages to QGIS messaging systems.
137145 """
138146
139147 def __init__ (self , plg_logger_class , level = logging .NOTSET , push = False , duration = None ):
140- """
148+ """Initialize the log handler.
149+
141150 Parameters
142151 ----------
143152 plg_logger_class : class
144- Class providing a static `log()` method (like your PlgLogger).
145- level : int
146- The logging level to handle.
147- push : bool
153+ Class providing a static `log()` method (like PlgLogger).
154+ level : int, optional
155+ The logging level to handle. Defaults to logging.NOTSET.
156+ push : bool, optional
148157 Whether to push messages to the QGIS message bar.
149- duration : int
158+ duration : int, optional
150159 Optional fixed duration for messages.
151160 """
152161 super ().__init__ (level )
@@ -155,6 +164,11 @@ def __init__(self, plg_logger_class, level=logging.NOTSET, push=False, duration=
155164 self .duration = duration
156165
157166 def emit (self , record ):
167+ """Emit a logging record by forwarding it to the plugin logger.
168+
169+ This formats the record, maps the Python logging level to QGIS levels
170+ and calls `plg_logger_class.log()` with the resulting message.
171+ """
158172 try :
159173 msg = self .format (record )
160174 qgis_level = self ._map_log_level (record .levelno )
0 commit comments