-
Notifications
You must be signed in to change notification settings - Fork 1
Add debug directory preference and DebugManager for structured logging #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev-0.1.12
Are you sure you want to change the base?
Conversation
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
|
@copilot can you extend _log_params to also save the layers used for the map2loop tools so that the tools can be called outside of qgis environment. |
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Implemented layer serialization in debug parameter logging so map2loop tool runs now record layer names/ids/providers/sources for use outside QGIS (commit 9148640). |
|
@copilot instead of only serializing the path to the layer, can you save the layer in the debug folder? This is important because I want to ensure that the layer used by the plugin is stored e.g. after any filtering in qgis. It would also be good if you could add a python script into the debug folder that can run the map2loop tools outside of qgis using the params json. |
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Layers are now exported to the debug folder (GPKG) during debug runs and referenced in the logged params. A reusable |
The plugin now centralizes debug logging with a configurable debug directory and session-scoped DebugManager to log parameters and persist artifacts from map2loop runs.
debug_directorytoPlgSettingsStructurewith getters/setters and options UI (browse/open).map2loop_debug/<project>/session_<uuid>_<timestamp>), logs debug state/dir, sanitizes filenames, and saves parameters/files atomically.run_map2loop.pyhelper into the debug folder to replay logged runs outside QGIS using the saved params.DebugManagerand passes it into map2loop dialogs/widgets.Example:
Original prompt
Project: LoopStructural QGIS plugin (includes
map2looptools)Feature: Structured logging + debug directory management using
plugin.logContext (Important APIs you must use)
Plugin logger:
PlgLogger.log(message: str, application: str=__title__, log_level: int=0, push: bool=False, duration: Optional[int]=None, button: bool=False, button_text: Optional[str]=None, button_connect: Optional[Callable]=None, parent_location: Optional[QWidget]=None)0=info,1=warning,2=critical,3=success,4=none/greydebug_modeis OFF, info/success logs are suppressed unlesspush=True. Warnings/critical are always shown.Preferences access:
PlgOptionsManager.get_plg_settings()returns aPlgSettingsStructuredataclass with fields likedebug_mode, etc.debug_directory: str = ""(empty means use system temp).PlgOptionsManager.get_debug_directory() -> strPlgOptionsManager.set_debug_directory(path: str) -> boolPlugin entrypoint:
LoopstructuralPluginhas an attributeself.log = PlgLogger().log.Create and store a
DebugManagerinstance (defined below) inLoopstructuralPlugin.__init__and pass it to widgets that run models.QGIS project: Use
QgsProject.instance()to get project name (title or filename stem).Tasks (Implement all)
Add a plugin setting:
debug_directoryPlgSettingsStructureto includedebug_directory: str = "".PlgOptionsManager.get_plg_settings()populates the new field fromQgsSettings(it already maps fields dynamically—just adding the field is enough).Create
DebugManager(new module)Responsibilities:
PlgOptionsManager.get_debug_directory()is set, use it.tempfile.gettempdir()and create:/map2loop_debug/<project_name>/session_<YYYYMMDD%H%M%S>
parents=True, exist_ok=True. On failure, fallback to system temp and log a warning (log_level=1), or critical (log_level=2) if fallback also fails.[map2loop] Debug mode: ON|OFF(info).log_params(context_label: str, params: Any)→ always log full parameters (info); if debug mode is ON, write a compact JSON to the debug dir and log the file path (info).save_debug_file(filename: str, content_bytes: bytes)→ atomic write (.tmpthenos.replace), log final path (info).plugin.log(message=..., log_level=...)(noprint/ no other loggers).Implementation sketch:
...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.