mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-01-14 19:43:05 +01:00
minor logging improvement
This commit is contained in:
@@ -6,16 +6,16 @@ from threading import Thread, Timer
|
||||
from gi.repository import GLib
|
||||
|
||||
_LOG_FILE = "demon-editor.log"
|
||||
_DATE_FORMAT = "%d-%m-%y %H:%M:%S"
|
||||
|
||||
LOG_DATE_FORMAT = "%d-%m-%y %H:%M:%S"
|
||||
LOGGER_NAME = "main_logger"
|
||||
LOG_FORMAT = "%(asctime)s %(message)s"
|
||||
|
||||
|
||||
def init_logger():
|
||||
logging.Logger(LOGGER_NAME)
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
format="%(asctime)s %(message)s",
|
||||
datefmt=_DATE_FORMAT,
|
||||
format=LOG_FORMAT,
|
||||
datefmt=LOG_DATE_FORMAT,
|
||||
handlers=[logging.FileHandler(_LOG_FILE), logging.StreamHandler()])
|
||||
log("Logging is enabled.", level=logging.INFO)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ from datetime import datetime
|
||||
|
||||
from gi.repository import Gdk, Gtk, GObject
|
||||
|
||||
from app.commons import run_task, log, _DATE_FORMAT, run_with_delay
|
||||
from app.commons import run_task, log, LOG_DATE_FORMAT, run_with_delay
|
||||
from app.settings import IS_DARWIN, IS_LINUX, IS_WIN
|
||||
|
||||
|
||||
@@ -528,7 +528,7 @@ class Recorder:
|
||||
|
||||
path = self._settings.records_path
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
d_now = datetime.now().strftime(_DATE_FORMAT)
|
||||
d_now = datetime.now().strftime(LOG_DATE_FORMAT)
|
||||
d_now = d_now.replace(" ", "_").replace(":", "-") if IS_WIN else d_now.replace(" ", "_")
|
||||
path = f"{path}{name.replace(' ', '_')}_{d_now}"
|
||||
cmd = self.get_transcoding_cmd(path) if self._settings.activate_transcoding else self._CMD.format(path)
|
||||
|
||||
@@ -30,7 +30,7 @@ import logging
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
from app.commons import LOGGER_NAME
|
||||
from app.commons import LOGGER_NAME, LOG_FORMAT, LOG_DATE_FORMAT
|
||||
from app.ui.dialogs import get_builder
|
||||
from app.ui.main_helper import append_text_to_tview
|
||||
from app.ui.uicommons import Gtk, UI_RESOURCES_PATH
|
||||
@@ -43,9 +43,10 @@ class LogsClient(Gtk.Box):
|
||||
def __init__(self, view):
|
||||
logging.Handler.__init__(self)
|
||||
self._view = view
|
||||
self.setFormatter(logging.Formatter(fmt=LOG_FORMAT, datefmt=LOG_DATE_FORMAT))
|
||||
|
||||
def handle(self, rec):
|
||||
GLib.idle_add(append_text_to_tview, f"{rec.msg}\n", self._view)
|
||||
def handle(self, rec: logging.LogRecord):
|
||||
GLib.idle_add(append_text_to_tview, f"{self.format(rec)}\n", self._view)
|
||||
|
||||
def __init__(self, app, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -67,3 +68,7 @@ class LogsClient(Gtk.Box):
|
||||
|
||||
def on_close(self, button):
|
||||
self._app.change_action_state("on_logs_show", GLib.Variant.new_boolean(False))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user