nfo 0.1.9__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.
nfo-0.1.9/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
nfo-0.1.9/PKG-INFO ADDED
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: nfo
3
+ Version: 0.1.9
4
+ Summary: Automatic function logging with decorators — output to SQLite, CSV, and Markdown
5
+ Author: wronai
6
+ License-Expression: Apache-2.0
7
+ Keywords: logging,decorator,sqlite,csv,markdown,auto-logging
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: System :: Logging
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0; extra == "dev"
23
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # lg
27
+
28
+
29
+ Tak, istnieją biblioteki Pythona, które automatyzują generowanie logów w funkcjach na podstawie analizy kodu, typów danych czy struktur jak try-except.
30
+
31
+ ## Loguru
32
+ Loguru to popularna biblioteka oferująca dekoratory do automatycznego logowania wejścia/wyjścia funkcji oraz wyjątków.
33
+ Używa się jej prosto: `@loguru.logger.catch` na funkcji automatycznie przechwytuje błędy i loguje szczegóły, w tym argumenty i typy.
34
+ Przykład: dekorator loguje parametry wejściowe, wyjątki z traceback oraz czas wykonania bez pisania ręcznych logów. [pktiuk.github](https://pktiuk.github.io/notatki_z_jezykow/Python%F0%9F%90%8D/4_biblioteki_i_narz%C4%99dzia/)
35
+
36
+ ## Decorator logowania
37
+ Biblioteka `funcy` lub proste dekoratory z `functools` pozwalają tworzyć customowe wrappery analizujące `inspect.signature()` dla typów argumentów.
38
+ Można dynamicznie logować nazwy parametrów, ich typy (`type(arg)`) i wartości przy wejściu/wyjściu.
39
+ Dla zaawansowanych przypadków `pydantic` integruje walidację typów z automatycznymi logami błędów walidacji w blokach try-except. [bulldogjob](https://bulldogjob.pl/readme/przewodnik-dla-poczatkujacych-po-pydantic-pythona)
40
+
41
+ ## Funkcjonalne podejście
42
+ Własny dekorator z `inspect` i `logging` może skanować strukturę kodu (ast.parse) i generować logi debug na podstawie obecności try-catch czy typów.
43
+ Biblioteki jak `wrapt` ułatwiają takie wrappingi bez modyfikacji oryginalnych funkcji.
44
+ To idealne dla Twoich projektów z embedded systems i automatyzacją, gdzie chcesz minimalizować boilerplate. [pktiuk.github](https://pktiuk.github.io/notatki_z_jezykow/Python%F0%9F%90%8D/4_biblioteki_i_narz%C4%99dzia/)
45
+
46
+
47
+
48
+ Tak, Loguru i standardowy logging z custom handlerami umożliwiają eksport logów bezpośrednio do SQLite, CSV czy Markdown poprzez konfigurację sinków lub handlerów. Poniżej przykłady użycia z automatycznym logowaniem (dekoratory) i outputem do plików.
49
+
50
+ ## Przykład Loguru z dekoratorem i CSV
51
+ Loguru pozwala dodać sink do pliku CSV, logując automatycznie argumenty, wyjątki z try-catch i typy danych.
52
+
53
+ ```python
54
+ from loguru import logger
55
+
56
+ # Dodaj sink CSV (automatycznie strukturyzuje logi)
57
+ logger.add("logs.csv", format="{time} | {level} | {name}:{function}:{line} | {message}", serialize=True)
58
+
59
+ @logger.catch # Automatycznie loguje wejście/wyjście i wyjątki
60
+ def moja_funkcja(x: int, y: str):
61
+ return x / len(y) # Przykładowy błąd
62
+
63
+ moja_funkcja(10, "") # Loguje do CSV z typami i traceback [web:23][web:13]
64
+ ```
65
+
66
+ Wynik w CSV: kolumny jak time, level, message z JSON-serializowanymi danymi (argumenty, typy). [github](https://github.com/Delgan/loguru/blob/master/README.md)
67
+
68
+ ## Loguru do Markdown
69
+ Loguru sink do Markdown generuje czytelne logi z nagłówkami i formatowaniem.
70
+
71
+ ```python
72
+ logger.add("logs.md", format="## {time:YYYY-MM-DD HH:mm:ss} | {level}\n{ message }\n", colorize=False)
73
+
74
+ @logger.catch
75
+ def test_funkcja(data):
76
+ raise ValueError("Błąd typów")
77
+
78
+ test_funkcja({"key": "value"}) # Logi z markdown: ## nagłówki, kody bloków [web:21]
79
+ ```
80
+
81
+ Plik MD: struktura z datą, poziomem, pełnym traceback i zmiennymi. [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/)
82
+
83
+ ## SQLite Handler dla logging/Loguru
84
+ Użyj `python-sqlite-log-handler` lub custom handler do bazy danych; integruje z dekoratorami.
85
+
86
+ ```python
87
+ import logging
88
+ from python_sqlite_log_handler import SQLiteLogHandler # pip install python-sqlite-log-handler
89
+
90
+ logger = logging.getLogger("app")
91
+ handler = SQLiteLogHandler(db_path="logs.db") # Tworzy tabelę logs
92
+ logger.addHandler(handler)
93
+ logger.setLevel(logging.DEBUG)
94
+
95
+ def try_catch_logger(func):
96
+ def wrapper(*args, **kwargs):
97
+ try:
98
+ return func(*args, **kwargs)
99
+ except Exception as e:
100
+ logger.error(f"Błąd w {func.__name__}: {e}", exc_info=True)
101
+ raise
102
+ return wrapper
103
+
104
+ @try_catch_logger
105
+ def funkcja_z_db(arg: dict):
106
+ if not arg: raise KeyError("Brak danych")
107
+
108
+ funkcja_z_db({}) # Loguje do SQLite: created_at, level, message, extra z typami [web:15][web:12]
109
+ ```
110
+
111
+ Query SQL: `SELECT * FROM logs WHERE level >= 30` – łatwe filtrowanie. [pypi](https://pypi.org/project/python-sqlite-log-handler/)
112
+
113
+ ## Porównanie outputów
114
+ | Biblioteka/Handler | SQLite | CSV | Markdown | Automatyczne dekoratory |
115
+ |--------------------|--------|-----|----------|------------------------|
116
+ | Loguru | Tak (custom sink) [stackoverflow](https://stackoverflow.com/questions/67693767/how-do-i-create-an-sqlite-3-database-handler-for-my-python-logger) | Tak (serialize=True) [github](https://github.com/Delgan/loguru/blob/master/README.md) | Tak (format MD) [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) | @logger.catch [datacamp](https://www.datacamp.com/tutorial/loguru-python-logging-tutorial) |
117
+ | logging + sqlite-handler | Tak (natywnie) [pypi](https://pypi.org/project/python-sqlite-log-handler/) | Tak (CSVHandler) | Custom formatter | Custom @try_catch [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) |
118
+
119
+
120
+
121
+
122
+ ## Analiza rozwiązań do automatycznego logowania w Pythonie
123
+
124
+ Istnieją cztery główne biblioteki umożliwiające automatyczne logi w funkcjach na bazie typów danych, struktur kodu (try-catch) i dekoratorów. Loguru jest najpopularniejszy (15k+ gwiazdek GitHub), structlog skupia się na strukturyzowanych logach, Eliot na wizualizacji, a standardowy logging z rozszerzeniami na elastyczność. [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/)
125
+
126
+ ## Szczegółowa tabela porównawcza
127
+
128
+ | Biblioteka | Automatyczne logi (dekoratory) | Analiza typów/struktury kodu | Obsługa SQLite | Obsługa CSV | Obsługa Markdown | Zalety | Wady | GitHub Stars (2026) | Ostatnia aktualizacja |
129
+ |------------------|-------------------------------|------------------------------|----------------|-------------|------------------|--------|------|---------------------|-----------------------|
130
+ | **Loguru** [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Tak (@logger.catch: wejście/wyjście, wyjątki, traceback) | Częściowa (loguje args via inspect, typy w serializacji) | Tak (custom sink z sqlite3) [stackoverflow](https://stackoverflow.com/questions/67693767/how-do-i-create-an-sqlite-3-database-handler-for-my-python-logger) | Tak (serialize=True, CSV format) [github](https://github.com/Delgan/loguru/blob/master/README.md) | Tak (custom format z ## nagłówkami) [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) | Zero-config, rotation plików, structured JSON, kolorowanie | Nie threaded-safe domyślnie | 15k+ [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Aktywna (2024-12) [pypi](https://pypi.org/project/loguru/) |
131
+ | **structlog** [matthewstrawbridge](https://www.matthewstrawbridge.com/content/2024/python-logging-basic-better-best/) | Tak (bind_context, processors dla func args) | Tak (structured metadata z typami, AST via processors) | Tak (via JSON + sqlite insert) [stackoverflow](https://stackoverflow.com/questions/67693767/how-do-i-create-an-sqlite-3-database-handler-for-my-python-logger) | Tak (JSON/CSV processors) | Tak (custom renderer) | Structured logs, async, OpenTelemetry | Więcej configu niż Loguru | Wysokie (top 6) [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Aktywna [dash0](https://www.dash0.com/guides/python-logging-with-structlog) |
132
+ | **Eliot** [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Tak (@log_call: pełne wejście/wyjście funkcji) | Tak (strukturyzowane eventy z typami) | Tak (JSON do SQLite) | Tak (JSON export) | Częściowa (JSON -> MD via tree) | Wizualizacja (eliot-tree CLI), narracyjne logi | Brak poziomów logów | Średnie [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Stabilna |
133
+ | **logging std + handlers** [reddit](https://www.reddit.com/r/Python/comments/1p6qy1e/spent_a_bunch_of_time_choosing_between_loguru/) | Tak (custom @decorator z inspect/traceback) [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) | Tak (via inspect.signature, ast.parse) | Tak (python-sqlite-log-handler) [pypi](https://pypi.org/project/python-sqlite-log-handler/) | Tak (CSVHandler/FileHandler) | Tak (custom Formatter) | Natywny, config files, threaded | Boilerplate bez dekoratorów | Wbudowany | Python 3.14 [docs.python](https://docs.python.org/pl/3/tutorial/errors.html) |
134
+
135
+ ## Rekomendacje dla Twoich projektów
136
+ Dla embedded/automatyzacji (RPi/ESP32) wybierz **Loguru** – prosty, lekki, integruje z Docker/K8s. Do biznesu (ERP/legal) **structlog** dla searchable JSON/SQLite. Przykłady kodu z poprzednich odpowiedzi działają out-of-box po `pip install loguru python-sqlite-log-handler`. [reddit](https://www.reddit.com/r/Python/comments/1p6qy1e/spent_a_bunch_of_time_choosing_between_loguru/)
137
+
138
+
139
+
140
+ W dobie LLM i multisrodowiskowych aplikacji (embedded, Docker/K8s, CI/CD) brakuje kilku kluczowych funkcji w bibliotekach logujących jak Loguru/structlog.
141
+
142
+ ## Braki w automatycznym logowaniu
143
+
144
+ **Brak natywnej integracji z LLM do kontekstowego parsowania logów**
145
+ Żadna biblioteka nie analizuje logów przez LLM w locie (np. "ten wyjątek TypeError sugeruje brak walidacji int w argumencie x") ani nie generuje sugestii fixów bezpośrednio w logu. W CI/CD z LLM to kluczowe dla szybkiej iteracji. [ijamjournal](https://ijamjournal.org/ijam/publication/index.php/ijam/article/view/77/)
146
+
147
+ ## Tabela brakujących funkcji
148
+
149
+ | Brakująca funkcja | Opis problemu | Przykład zastosowania w Twoich projektach |
150
+ |-------------------|---------------|------------------------------------------|
151
+ | **LLM-powered log parsing** | Logi tylko statyczne; brak AI do grupowania podobnych błędów czy predykcji root cause | W embedded RPi: LLM grupuje "I2C timeout" z sensorami i sugeruje "sprawdź zasilanie" |
152
+ | **Multi-env log correlation** | Brak automatycznego tagowania środowisk (dev/staging/prod) + trace ID dla K8s pods | CI/CD deploy do Docker: brak linku "błąd w pod-3 → Git commit abc123" |
153
+ | **Dynamic sink routing** | Ręczne config sinków (SQLite/CSV); brak auto-przełączania na bazie env/variable types | Prod → Elasticsearch, dev → Markdown; bez config files |
154
+ | **Structured diff logs** | Nie loguje zmian input/output między wersjami funkcji w CI/CD | A/B test funkcji: "v1.2.1 input dict → output None, v1.2.2 → output list" |
155
+ | **Prompt injection detection** | Brak auto-detektu LLM prompt injection w logach API calls | Twoja automatyzacja prawna: loguje "znajdź lukę w umowie X" → flaga bezpieczeństwa |
156
+
157
+ ## Proponowane rozszerzenia dla CI/CD + LLM
158
+
159
+ ```python
160
+ # Wyobrażone Loguru 3.0 z LLM integration
161
+ from loguru_llm import LLMAnalyzer
162
+
163
+ @logger.catch(llm_analyzer=LLMAnalyzer(model="gpt-4o-mini"))
164
+ def risky_function(user_input: str):
165
+ # LLM auto-parsuje exception i dodaje: "Prawdopodobna przyczyna: SQL injection"
166
+ return eval(user_input) # danger!
167
+ ```
168
+
169
+ **Dla Twoich projektów**: Stwórz custom sink z LangChain + Pinecone vector DB do semantycznego searchu logów ("pokaż wszystkie TypeError z dict arg w ciągu 7 dni") i GitHub Actions step z LLM code review na bazie logów z failed builds. [github](https://github.com/charliepaks/llm-cicd)
nfo-0.1.9/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # lg
2
+
3
+
4
+ Tak, istnieją biblioteki Pythona, które automatyzują generowanie logów w funkcjach na podstawie analizy kodu, typów danych czy struktur jak try-except.
5
+
6
+ ## Loguru
7
+ Loguru to popularna biblioteka oferująca dekoratory do automatycznego logowania wejścia/wyjścia funkcji oraz wyjątków.
8
+ Używa się jej prosto: `@loguru.logger.catch` na funkcji automatycznie przechwytuje błędy i loguje szczegóły, w tym argumenty i typy.
9
+ Przykład: dekorator loguje parametry wejściowe, wyjątki z traceback oraz czas wykonania bez pisania ręcznych logów. [pktiuk.github](https://pktiuk.github.io/notatki_z_jezykow/Python%F0%9F%90%8D/4_biblioteki_i_narz%C4%99dzia/)
10
+
11
+ ## Decorator logowania
12
+ Biblioteka `funcy` lub proste dekoratory z `functools` pozwalają tworzyć customowe wrappery analizujące `inspect.signature()` dla typów argumentów.
13
+ Można dynamicznie logować nazwy parametrów, ich typy (`type(arg)`) i wartości przy wejściu/wyjściu.
14
+ Dla zaawansowanych przypadków `pydantic` integruje walidację typów z automatycznymi logami błędów walidacji w blokach try-except. [bulldogjob](https://bulldogjob.pl/readme/przewodnik-dla-poczatkujacych-po-pydantic-pythona)
15
+
16
+ ## Funkcjonalne podejście
17
+ Własny dekorator z `inspect` i `logging` może skanować strukturę kodu (ast.parse) i generować logi debug na podstawie obecności try-catch czy typów.
18
+ Biblioteki jak `wrapt` ułatwiają takie wrappingi bez modyfikacji oryginalnych funkcji.
19
+ To idealne dla Twoich projektów z embedded systems i automatyzacją, gdzie chcesz minimalizować boilerplate. [pktiuk.github](https://pktiuk.github.io/notatki_z_jezykow/Python%F0%9F%90%8D/4_biblioteki_i_narz%C4%99dzia/)
20
+
21
+
22
+
23
+ Tak, Loguru i standardowy logging z custom handlerami umożliwiają eksport logów bezpośrednio do SQLite, CSV czy Markdown poprzez konfigurację sinków lub handlerów. Poniżej przykłady użycia z automatycznym logowaniem (dekoratory) i outputem do plików.
24
+
25
+ ## Przykład Loguru z dekoratorem i CSV
26
+ Loguru pozwala dodać sink do pliku CSV, logując automatycznie argumenty, wyjątki z try-catch i typy danych.
27
+
28
+ ```python
29
+ from loguru import logger
30
+
31
+ # Dodaj sink CSV (automatycznie strukturyzuje logi)
32
+ logger.add("logs.csv", format="{time} | {level} | {name}:{function}:{line} | {message}", serialize=True)
33
+
34
+ @logger.catch # Automatycznie loguje wejście/wyjście i wyjątki
35
+ def moja_funkcja(x: int, y: str):
36
+ return x / len(y) # Przykładowy błąd
37
+
38
+ moja_funkcja(10, "") # Loguje do CSV z typami i traceback [web:23][web:13]
39
+ ```
40
+
41
+ Wynik w CSV: kolumny jak time, level, message z JSON-serializowanymi danymi (argumenty, typy). [github](https://github.com/Delgan/loguru/blob/master/README.md)
42
+
43
+ ## Loguru do Markdown
44
+ Loguru sink do Markdown generuje czytelne logi z nagłówkami i formatowaniem.
45
+
46
+ ```python
47
+ logger.add("logs.md", format="## {time:YYYY-MM-DD HH:mm:ss} | {level}\n{ message }\n", colorize=False)
48
+
49
+ @logger.catch
50
+ def test_funkcja(data):
51
+ raise ValueError("Błąd typów")
52
+
53
+ test_funkcja({"key": "value"}) # Logi z markdown: ## nagłówki, kody bloków [web:21]
54
+ ```
55
+
56
+ Plik MD: struktura z datą, poziomem, pełnym traceback i zmiennymi. [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/)
57
+
58
+ ## SQLite Handler dla logging/Loguru
59
+ Użyj `python-sqlite-log-handler` lub custom handler do bazy danych; integruje z dekoratorami.
60
+
61
+ ```python
62
+ import logging
63
+ from python_sqlite_log_handler import SQLiteLogHandler # pip install python-sqlite-log-handler
64
+
65
+ logger = logging.getLogger("app")
66
+ handler = SQLiteLogHandler(db_path="logs.db") # Tworzy tabelę logs
67
+ logger.addHandler(handler)
68
+ logger.setLevel(logging.DEBUG)
69
+
70
+ def try_catch_logger(func):
71
+ def wrapper(*args, **kwargs):
72
+ try:
73
+ return func(*args, **kwargs)
74
+ except Exception as e:
75
+ logger.error(f"Błąd w {func.__name__}: {e}", exc_info=True)
76
+ raise
77
+ return wrapper
78
+
79
+ @try_catch_logger
80
+ def funkcja_z_db(arg: dict):
81
+ if not arg: raise KeyError("Brak danych")
82
+
83
+ funkcja_z_db({}) # Loguje do SQLite: created_at, level, message, extra z typami [web:15][web:12]
84
+ ```
85
+
86
+ Query SQL: `SELECT * FROM logs WHERE level >= 30` – łatwe filtrowanie. [pypi](https://pypi.org/project/python-sqlite-log-handler/)
87
+
88
+ ## Porównanie outputów
89
+ | Biblioteka/Handler | SQLite | CSV | Markdown | Automatyczne dekoratory |
90
+ |--------------------|--------|-----|----------|------------------------|
91
+ | Loguru | Tak (custom sink) [stackoverflow](https://stackoverflow.com/questions/67693767/how-do-i-create-an-sqlite-3-database-handler-for-my-python-logger) | Tak (serialize=True) [github](https://github.com/Delgan/loguru/blob/master/README.md) | Tak (format MD) [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) | @logger.catch [datacamp](https://www.datacamp.com/tutorial/loguru-python-logging-tutorial) |
92
+ | logging + sqlite-handler | Tak (natywnie) [pypi](https://pypi.org/project/python-sqlite-log-handler/) | Tak (CSVHandler) | Custom formatter | Custom @try_catch [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) |
93
+
94
+
95
+
96
+
97
+ ## Analiza rozwiązań do automatycznego logowania w Pythonie
98
+
99
+ Istnieją cztery główne biblioteki umożliwiające automatyczne logi w funkcjach na bazie typów danych, struktur kodu (try-catch) i dekoratorów. Loguru jest najpopularniejszy (15k+ gwiazdek GitHub), structlog skupia się na strukturyzowanych logach, Eliot na wizualizacji, a standardowy logging z rozszerzeniami na elastyczność. [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/)
100
+
101
+ ## Szczegółowa tabela porównawcza
102
+
103
+ | Biblioteka | Automatyczne logi (dekoratory) | Analiza typów/struktury kodu | Obsługa SQLite | Obsługa CSV | Obsługa Markdown | Zalety | Wady | GitHub Stars (2026) | Ostatnia aktualizacja |
104
+ |------------------|-------------------------------|------------------------------|----------------|-------------|------------------|--------|------|---------------------|-----------------------|
105
+ | **Loguru** [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Tak (@logger.catch: wejście/wyjście, wyjątki, traceback) | Częściowa (loguje args via inspect, typy w serializacji) | Tak (custom sink z sqlite3) [stackoverflow](https://stackoverflow.com/questions/67693767/how-do-i-create-an-sqlite-3-database-handler-for-my-python-logger) | Tak (serialize=True, CSV format) [github](https://github.com/Delgan/loguru/blob/master/README.md) | Tak (custom format z ## nagłówkami) [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) | Zero-config, rotation plików, structured JSON, kolorowanie | Nie threaded-safe domyślnie | 15k+ [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Aktywna (2024-12) [pypi](https://pypi.org/project/loguru/) |
106
+ | **structlog** [matthewstrawbridge](https://www.matthewstrawbridge.com/content/2024/python-logging-basic-better-best/) | Tak (bind_context, processors dla func args) | Tak (structured metadata z typami, AST via processors) | Tak (via JSON + sqlite insert) [stackoverflow](https://stackoverflow.com/questions/67693767/how-do-i-create-an-sqlite-3-database-handler-for-my-python-logger) | Tak (JSON/CSV processors) | Tak (custom renderer) | Structured logs, async, OpenTelemetry | Więcej configu niż Loguru | Wysokie (top 6) [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Aktywna [dash0](https://www.dash0.com/guides/python-logging-with-structlog) |
107
+ | **Eliot** [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Tak (@log_call: pełne wejście/wyjście funkcji) | Tak (strukturyzowane eventy z typami) | Tak (JSON do SQLite) | Tak (JSON export) | Częściowa (JSON -> MD via tree) | Wizualizacja (eliot-tree CLI), narracyjne logi | Brak poziomów logów | Średnie [betterstack](https://betterstack.com/community/guides/logging/best-python-logging-libraries/) | Stabilna |
108
+ | **logging std + handlers** [reddit](https://www.reddit.com/r/Python/comments/1p6qy1e/spent_a_bunch_of_time_choosing_between_loguru/) | Tak (custom @decorator z inspect/traceback) [jojoduquartier.github](https://jojoduquartier.github.io/snippets/logging_decorator/) | Tak (via inspect.signature, ast.parse) | Tak (python-sqlite-log-handler) [pypi](https://pypi.org/project/python-sqlite-log-handler/) | Tak (CSVHandler/FileHandler) | Tak (custom Formatter) | Natywny, config files, threaded | Boilerplate bez dekoratorów | Wbudowany | Python 3.14 [docs.python](https://docs.python.org/pl/3/tutorial/errors.html) |
109
+
110
+ ## Rekomendacje dla Twoich projektów
111
+ Dla embedded/automatyzacji (RPi/ESP32) wybierz **Loguru** – prosty, lekki, integruje z Docker/K8s. Do biznesu (ERP/legal) **structlog** dla searchable JSON/SQLite. Przykłady kodu z poprzednich odpowiedzi działają out-of-box po `pip install loguru python-sqlite-log-handler`. [reddit](https://www.reddit.com/r/Python/comments/1p6qy1e/spent_a_bunch_of_time_choosing_between_loguru/)
112
+
113
+
114
+
115
+ W dobie LLM i multisrodowiskowych aplikacji (embedded, Docker/K8s, CI/CD) brakuje kilku kluczowych funkcji w bibliotekach logujących jak Loguru/structlog.
116
+
117
+ ## Braki w automatycznym logowaniu
118
+
119
+ **Brak natywnej integracji z LLM do kontekstowego parsowania logów**
120
+ Żadna biblioteka nie analizuje logów przez LLM w locie (np. "ten wyjątek TypeError sugeruje brak walidacji int w argumencie x") ani nie generuje sugestii fixów bezpośrednio w logu. W CI/CD z LLM to kluczowe dla szybkiej iteracji. [ijamjournal](https://ijamjournal.org/ijam/publication/index.php/ijam/article/view/77/)
121
+
122
+ ## Tabela brakujących funkcji
123
+
124
+ | Brakująca funkcja | Opis problemu | Przykład zastosowania w Twoich projektach |
125
+ |-------------------|---------------|------------------------------------------|
126
+ | **LLM-powered log parsing** | Logi tylko statyczne; brak AI do grupowania podobnych błędów czy predykcji root cause | W embedded RPi: LLM grupuje "I2C timeout" z sensorami i sugeruje "sprawdź zasilanie" |
127
+ | **Multi-env log correlation** | Brak automatycznego tagowania środowisk (dev/staging/prod) + trace ID dla K8s pods | CI/CD deploy do Docker: brak linku "błąd w pod-3 → Git commit abc123" |
128
+ | **Dynamic sink routing** | Ręczne config sinków (SQLite/CSV); brak auto-przełączania na bazie env/variable types | Prod → Elasticsearch, dev → Markdown; bez config files |
129
+ | **Structured diff logs** | Nie loguje zmian input/output między wersjami funkcji w CI/CD | A/B test funkcji: "v1.2.1 input dict → output None, v1.2.2 → output list" |
130
+ | **Prompt injection detection** | Brak auto-detektu LLM prompt injection w logach API calls | Twoja automatyzacja prawna: loguje "znajdź lukę w umowie X" → flaga bezpieczeństwa |
131
+
132
+ ## Proponowane rozszerzenia dla CI/CD + LLM
133
+
134
+ ```python
135
+ # Wyobrażone Loguru 3.0 z LLM integration
136
+ from loguru_llm import LLMAnalyzer
137
+
138
+ @logger.catch(llm_analyzer=LLMAnalyzer(model="gpt-4o-mini"))
139
+ def risky_function(user_input: str):
140
+ # LLM auto-parsuje exception i dodaje: "Prawdopodobna przyczyna: SQL injection"
141
+ return eval(user_input) # danger!
142
+ ```
143
+
144
+ **Dla Twoich projektów**: Stwórz custom sink z LangChain + Pinecone vector DB do semantycznego searchu logów ("pokaż wszystkie TypeError z dict arg w ciągu 7 dni") i GitHub Actions step z LLM code review na bazie logów z failed builds. [github](https://github.com/charliepaks/llm-cicd)
@@ -0,0 +1,20 @@
1
+ """
2
+ lg — Automatic function logging with decorators.
3
+
4
+ Output to SQLite, CSV, and Markdown.
5
+ """
6
+
7
+ from lg.decorators import log_call, catch
8
+ from lg.logger import Logger
9
+ from lg.sinks import SQLiteSink, CSVSink, MarkdownSink
10
+
11
+ __version__ = "0.1.0"
12
+
13
+ __all__ = [
14
+ "log_call",
15
+ "catch",
16
+ "Logger",
17
+ "SQLiteSink",
18
+ "CSVSink",
19
+ "MarkdownSink",
20
+ ]