Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
765cc061c1 | ||
|
|
80319385f0 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.22.0"
|
version = "0.22.1"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import logging
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import atexit
|
||||||
from typing import MutableMapping, TextIO, TypedDict, Any, TYPE_CHECKING, cast
|
from typing import MutableMapping, TextIO, TypedDict, Any, TYPE_CHECKING, cast
|
||||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||||
from corelibs.string_handling.text_colors import Colors
|
from corelibs.string_handling.text_colors import Colors
|
||||||
@@ -121,6 +122,9 @@ class LogParent:
|
|||||||
self.log_queue: 'Queue[str] | None' = None
|
self.log_queue: 'Queue[str] | None' = None
|
||||||
self.handlers: dict[str, Any] = {}
|
self.handlers: dict[str, Any] = {}
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self._cleanup()
|
||||||
|
|
||||||
# FIXME: we need to add a custom formater to add stack level listing if we want to
|
# FIXME: we need to add a custom formater to add stack level listing if we want to
|
||||||
# Important note, although they exist, it is recommended to use self.logger.NAME directly
|
# Important note, although they exist, it is recommended to use self.logger.NAME directly
|
||||||
# so that the correct filename, method and row number is set
|
# so that the correct filename, method and row number is set
|
||||||
@@ -282,6 +286,15 @@ class LogParent:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _cleanup(self):
|
||||||
|
"""cleanup for any open queues in case we have an abort"""
|
||||||
|
if not self.log_queue:
|
||||||
|
return
|
||||||
|
self.flush()
|
||||||
|
# Close the queue properly
|
||||||
|
self.log_queue.close()
|
||||||
|
self.log_queue.join_thread()
|
||||||
|
|
||||||
# MARK: log level handling
|
# MARK: log level handling
|
||||||
def set_log_level(self, handler_name: str, log_level: LoggingLevel) -> bool:
|
def set_log_level(self, handler_name: str, log_level: LoggingLevel) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -634,6 +647,7 @@ class Log(LogParent):
|
|||||||
if log_queue is None:
|
if log_queue is None:
|
||||||
return
|
return
|
||||||
self.log_queue = log_queue
|
self.log_queue = log_queue
|
||||||
|
atexit.register(self._cleanup)
|
||||||
self.listener = logging.handlers.QueueListener(
|
self.listener = logging.handlers.QueueListener(
|
||||||
self.log_queue,
|
self.log_queue,
|
||||||
*self.handlers.values(),
|
*self.handlers.values(),
|
||||||
|
|||||||
4
uv.lock
generated
4
uv.lock
generated
@@ -1,5 +1,5 @@
|
|||||||
version = 1
|
version = 1
|
||||||
revision = 2
|
revision = 3
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -44,7 +44,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.21.0"
|
version = "0.22.0"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "jmespath" },
|
{ name = "jmespath" },
|
||||||
|
|||||||
Reference in New Issue
Block a user