|
36 | 36 | from .Globals import _run_coro_async |
37 | 37 | from .WidgetsCreator import ProgressDialog, CompilationProcessDialog |
38 | 38 | from .Venv_Manager import VenvManager |
39 | | -from .i18n import resolve_system_language, get_translations, tr_fr_en, is_french_language |
| 39 | +from .i18n import ( |
| 40 | + resolve_system_language, |
| 41 | + get_translations, |
| 42 | + tr_fr_en, |
| 43 | + is_french_language, |
| 44 | + log_with_level, |
| 45 | +) |
40 | 46 |
|
41 | 47 | # Import des fonctionnalités UI depuis UiFeatures |
42 | 48 | from .UiFeatures import UiFeatures |
@@ -324,18 +330,61 @@ def tr(self, fr: str, en: str) -> str: |
324 | 330 | # JOURNALISATION |
325 | 331 | # ========================================================================= |
326 | 332 |
|
| 333 | + def _infer_log_level(self, text) -> str: |
| 334 | + try: |
| 335 | + s = str(text or "").strip() |
| 336 | + except Exception: |
| 337 | + s = "" |
| 338 | + if not s: |
| 339 | + return "info" |
| 340 | + emoji_levels = { |
| 341 | + "❌": "error", |
| 342 | + "⚠️": "warning", |
| 343 | + "✅": "success", |
| 344 | + "ℹ️": "info", |
| 345 | + "📝": "state", |
| 346 | + "📋": "state", |
| 347 | + "🔍": "state", |
| 348 | + "🔧": "state", |
| 349 | + "🔨": "state", |
| 350 | + "➡️": "state", |
| 351 | + "📦": "state", |
| 352 | + "🗑️": "state", |
| 353 | + } |
| 354 | + for emoji, lvl in emoji_levels.items(): |
| 355 | + if s.startswith(emoji): |
| 356 | + return lvl |
| 357 | + low = s.lower() |
| 358 | + if any( |
| 359 | + tok in low |
| 360 | + for tok in ("error", "erreur", "échec", "echec", "failed", "invalid", "refus") |
| 361 | + ): |
| 362 | + return "error" |
| 363 | + if any(tok in low for tok in ("warning", "avert", "warn", "attention")): |
| 364 | + return "warning" |
| 365 | + if any(tok in low for tok in ("success", "succès", "reussi", "réussi")): |
| 366 | + return "success" |
| 367 | + if any(tok in low for tok in ("state", "status", "état", "etat")): |
| 368 | + return "state" |
| 369 | + return "info" |
| 370 | + |
327 | 371 | def _safe_log(self, text): |
328 | 372 | """Journalise de manière sécurisée.""" |
329 | 373 | try: |
330 | | - if hasattr(self, "log") and self.log: |
331 | | - self.log.append(text) |
332 | | - else: |
333 | | - print(text) |
| 374 | + level = self._infer_log_level(text) |
| 375 | + log_with_level(self, level, text) |
| 376 | + return |
334 | 377 | except Exception: |
335 | 378 | try: |
336 | | - print(text) |
| 379 | + if hasattr(self, "log") and self.log: |
| 380 | + self.log.append(text) |
| 381 | + else: |
| 382 | + print(text) |
337 | 383 | except Exception: |
338 | | - pass |
| 384 | + try: |
| 385 | + print(text) |
| 386 | + except Exception: |
| 387 | + pass |
339 | 388 |
|
340 | 389 | # ========================================================================= |
341 | 390 | # TÂCHES EN ARRIÈRE-PLAN |
|
0 commit comments