logurich 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
logurich-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 PakitoSec
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: logurich
3
+ Version: 0.1.0
4
+ Summary: A Python library combining Loguru and Rich for beautiful logging.
5
+ Author-email: PakitoSec <jeromep83@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/PakitoSec/logurich
8
+ Project-URL: Repository, https://github.com/PakitoSec/logurich
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Classifier: Topic :: System :: Logging
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: loguru
24
+ Requires-Dist: rich
25
+ Dynamic: license-file
26
+
27
+ # logurich
28
+
29
+ A Python library combining Loguru and Rich for beautiful logging.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install logurich
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ Logurich now supports direct imports from the package root, making it easier to access the logger and console:
40
+
41
+ ```python
42
+ # Import directly from the package root
43
+ from logurich import logger, console
44
+
45
+ # Use the logger
46
+ logger.info("This is a log message")
47
+
48
+ # Use rich color and rich object formatting
49
+ logger.info("[bold green]Rich formatted text[/bold green]")
50
+
51
+ # Panel rich object with logger and prefix
52
+ logger.rich(
53
+ "INFO", Panel("Rich Panel", border_style="green"), title="Rich Panel Object"
54
+ )
55
+
56
+ # Panel rich object without prefix
57
+ logger.rich(
58
+ "INFO",
59
+ Panel("Rich Panel without prefix", border_style="green"),
60
+ title="Rich Panel",
61
+ prefix=False,
62
+ )
63
+ ```
@@ -0,0 +1,37 @@
1
+ # logurich
2
+
3
+ A Python library combining Loguru and Rich for beautiful logging.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install logurich
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Logurich now supports direct imports from the package root, making it easier to access the logger and console:
14
+
15
+ ```python
16
+ # Import directly from the package root
17
+ from logurich import logger, console
18
+
19
+ # Use the logger
20
+ logger.info("This is a log message")
21
+
22
+ # Use rich color and rich object formatting
23
+ logger.info("[bold green]Rich formatted text[/bold green]")
24
+
25
+ # Panel rich object with logger and prefix
26
+ logger.rich(
27
+ "INFO", Panel("Rich Panel", border_style="green"), title="Rich Panel Object"
28
+ )
29
+
30
+ # Panel rich object without prefix
31
+ logger.rich(
32
+ "INFO",
33
+ Panel("Rich Panel without prefix", border_style="green"),
34
+ title="Rich Panel",
35
+ prefix=False,
36
+ )
37
+ ```
@@ -0,0 +1,29 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from .console import console, configure_console, get_console, rich_to_str, set_console
4
+ from .core import (
5
+ ContextValue,
6
+ ctx,
7
+ global_configure,
8
+ global_set_context,
9
+ init_logger,
10
+ logger,
11
+ mp_configure,
12
+ )
13
+
14
+ init_logger("INFO")
15
+
16
+ __all__ = [
17
+ "logger",
18
+ "init_logger",
19
+ "mp_configure",
20
+ "global_configure",
21
+ "global_set_context",
22
+ "ContextValue",
23
+ "ctx",
24
+ "console",
25
+ "configure_console",
26
+ "get_console",
27
+ "set_console",
28
+ "rich_to_str",
29
+ ]
@@ -0,0 +1,51 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import ContextManager, Final, Literal, Mapping, Protocol
4
+
5
+ from .core import ContextValue, LoguRich
6
+ from rich.console import Console
7
+
8
+ LogLevel = Literal["TRACE", "DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"]
9
+ LevelByModuleValue = str | int | bool
10
+ LevelByModuleMapping = Mapping[str | None, LevelByModuleValue]
11
+
12
+ class _SupportsStr(Protocol):
13
+ def __str__(self) -> str: ...
14
+
15
+ ContextBinding = ContextValue | _SupportsStr | None
16
+
17
+ __version__: Final[str]
18
+
19
+ logger: LoguRich
20
+ console: Console
21
+
22
+ def ctx(
23
+ value: object,
24
+ *,
25
+ style: str | None = None,
26
+ value_style: str | None = None,
27
+ bracket_style: str | None = None,
28
+ label: str | None = None,
29
+ show_key: bool | None = None,
30
+ ) -> ContextValue: ...
31
+ def init_logger(
32
+ log_level: LogLevel,
33
+ log_verbose: int = 0,
34
+ log_filename: str | None = None,
35
+ log_folder: str = "logs",
36
+ level_by_module: LevelByModuleMapping | None = None,
37
+ *,
38
+ rich_handler: bool = False,
39
+ diagnose: bool = False,
40
+ enqueue: bool = True,
41
+ highlight: bool = False,
42
+ ) -> str | None: ...
43
+ def mp_configure(logger_: LoguRich) -> None: ...
44
+ def global_configure(**kwargs: ContextBinding) -> ContextManager[None]: ...
45
+ def global_set_context(**kwargs: ContextBinding) -> None: ...
46
+ def configure_console(*args: object, **kwargs: object) -> Console: ...
47
+ def get_console() -> Console: ...
48
+ def set_console(console: Console) -> None: ...
49
+ def rich_to_str(*objects: object, ansi: bool = True, **kwargs: object) -> str: ...
50
+
51
+ __all__: Final[list[str]]
@@ -0,0 +1,96 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from rich.console import Console, ConsoleRenderable
6
+ from rich.pretty import Pretty
7
+ from rich.table import Table
8
+ from rich.text import Text
9
+
10
+ _console = None
11
+
12
+
13
+ def rich_to_str(*objects, ansi: bool = True, **kwargs) -> str:
14
+ console = get_console()
15
+ with console.capture() as capture:
16
+ console.print(*objects, **kwargs)
17
+ if ansi is True:
18
+ return capture.get()
19
+ return str(Text.from_ansi(capture.get()))
20
+
21
+
22
+ def rich_format_grid(prefix: Text, data: ConsoleRenderable, real_width: int) -> Table:
23
+ grid = Table.grid()
24
+ grid.add_column()
25
+ grid.add_column()
26
+ content = Text.from_ansi(rich_to_str(data, width=real_width, end=""))
27
+ lines = content.split()
28
+ for line in lines:
29
+ pline = prefix.copy()
30
+ grid.add_row(pline, line)
31
+ return grid
32
+
33
+
34
+ def rich_console_renderer(
35
+ prefix: str, rich_format: bool, data: Any
36
+ ) -> list[ConsoleRenderable]:
37
+ console = get_console()
38
+ rich_prefix = prefix[:-2] + "# "
39
+ pp = Text.from_markup(rich_prefix)
40
+ real_width = console.width - len(pp)
41
+ renderable = []
42
+ for r in data:
43
+ if rich_format:
44
+ if isinstance(r, str):
45
+ item = pp.copy()
46
+ item = item.append(Text.from_markup(r))
47
+ renderable.append(item)
48
+ elif isinstance(r, Text) and r.split() == 1:
49
+ item = pp.copy()
50
+ item = item.append_text(r)
51
+ renderable.append(item)
52
+ elif isinstance(r, ConsoleRenderable):
53
+ renderable.append(rich_format_grid(pp, r, real_width))
54
+ else:
55
+ renderable.append(
56
+ rich_format_grid(
57
+ pp, Pretty(r, max_depth=2, max_length=2), real_width
58
+ )
59
+ )
60
+ else:
61
+ if isinstance(r, str):
62
+ renderable.append(Text.from_ansi(r))
63
+ else:
64
+ renderable.append(r)
65
+ return renderable
66
+
67
+
68
+ def set_console(console: Console):
69
+ global _console
70
+ _console = console
71
+
72
+
73
+ def get_console() -> Console:
74
+ global _console
75
+ if _console is None:
76
+ _console = Console(markup=True)
77
+ return _console
78
+
79
+
80
+ def configure_console(*args: Any, **kwargs: Any) -> Console:
81
+ """Reconfigures the logurich console by replacing it with another.
82
+
83
+ Args:
84
+ *args (Any): Positional arguments for the replacement :class:`~rich.console.Console`.
85
+ **kwargs (Any): Keyword arguments for the replacement :class:`~rich.console.Console`.
86
+
87
+ Return:
88
+ Return the logurich console
89
+ """
90
+ new_console = Console(*args, **kwargs)
91
+ _console = get_console()
92
+ _console.__dict__ = new_console.__dict__
93
+ return _console
94
+
95
+
96
+ console = get_console()