balsa 0.0.4__tar.gz → 0.26.1__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.
Files changed (61) hide show
  1. balsa-0.26.1/.coveragerc +7 -0
  2. balsa-0.26.1/LICENSE +21 -0
  3. balsa-0.26.1/LICENSE.txt +21 -0
  4. balsa-0.26.1/MANIFEST.in +5 -0
  5. balsa-0.26.1/PKG-INFO +130 -0
  6. balsa-0.26.1/balsa/__init__.py +11 -0
  7. balsa-0.26.1/balsa/__version__.py +10 -0
  8. balsa-0.26.1/balsa/aws_cloudwatch_logs.py +86 -0
  9. balsa-0.26.1/balsa/balsa.py +482 -0
  10. balsa-0.26.1/balsa/formatter.py +16 -0
  11. balsa-0.26.1/balsa/get_logger.py +17 -0
  12. balsa-0.26.1/balsa/guihandler.py +170 -0
  13. balsa-0.26.1/balsa/handlers.py +42 -0
  14. balsa-0.26.1/balsa/py.typed +0 -0
  15. balsa-0.26.1/balsa/structured.py +100 -0
  16. balsa-0.26.1/balsa.egg-info/PKG-INFO +130 -0
  17. balsa-0.26.1/balsa.egg-info/SOURCES.txt +51 -0
  18. balsa-0.26.1/balsa.egg-info/requires.txt +6 -0
  19. balsa-0.26.1/pyproject.toml +41 -0
  20. balsa-0.26.1/pytest.ini +7 -0
  21. balsa-0.26.1/readme.rst +100 -0
  22. balsa-0.26.1/requirements-dev.txt +52 -0
  23. {balsa-0.0.4 → balsa-0.26.1}/setup.cfg +4 -4
  24. balsa-0.26.1/test_balsa/__init__.py +0 -0
  25. balsa-0.26.1/test_balsa/conftest.py +3 -0
  26. balsa-0.26.1/test_balsa/popup_window.py +29 -0
  27. balsa-0.26.1/test_balsa/test_a_global_balsa.py +29 -0
  28. balsa-0.26.1/test_balsa/test_balsa_args.py +17 -0
  29. balsa-0.26.1/test_balsa/test_balsa_aws_cloudwatch_logs.py +43 -0
  30. balsa-0.26.1/test_balsa/test_balsa_callback.py +29 -0
  31. balsa-0.26.1/test_balsa/test_balsa_clone.py +30 -0
  32. balsa-0.26.1/test_balsa/test_balsa_gui.py +32 -0
  33. balsa-0.26.1/test_balsa/test_balsa_gui_std.py +22 -0
  34. balsa-0.26.1/test_balsa/test_balsa_gui_std_too_low.py +30 -0
  35. balsa-0.26.1/test_balsa/test_balsa_simple.py +21 -0
  36. balsa-0.26.1/test_balsa/test_console_log_level.py +78 -0
  37. balsa-0.26.1/test_balsa/test_embedded_python.py +26 -0
  38. balsa-0.26.1/test_balsa/test_exception.py +32 -0
  39. balsa-0.26.1/test_balsa/test_gui_rate_limit.py +50 -0
  40. balsa-0.26.1/test_balsa/test_guihandler_hardening.py +104 -0
  41. balsa-0.26.1/test_balsa/test_log_string_to_object.py +67 -0
  42. balsa-0.26.1/test_balsa/test_multiprocessing.py +52 -0
  43. balsa-0.26.1/test_balsa/test_not_root.py +20 -0
  44. balsa-0.26.1/test_balsa/test_notes.txt +4 -0
  45. balsa-0.26.1/test_balsa/test_rate_limits_json.py +77 -0
  46. balsa-0.26.1/test_balsa/test_sentry.py +178 -0
  47. balsa-0.26.1/test_balsa/test_structured_logging.py +34 -0
  48. balsa-0.26.1/test_balsa/test_threaded_gui.py +106 -0
  49. balsa-0.26.1/test_balsa/test_two_logs.py +54 -0
  50. balsa-0.26.1/test_balsa/test_version.py +15 -0
  51. balsa-0.26.1/test_balsa/tst_balsa.py +70 -0
  52. balsa-0.0.4/PKG-INFO +0 -53
  53. balsa-0.0.4/balsa/__init__.py +0 -4
  54. balsa-0.0.4/balsa/__version__.py +0 -10
  55. balsa-0.0.4/balsa/balsa.py +0 -160
  56. balsa-0.0.4/balsa.egg-info/PKG-INFO +0 -53
  57. balsa-0.0.4/balsa.egg-info/SOURCES.txt +0 -9
  58. balsa-0.0.4/balsa.egg-info/requires.txt +0 -1
  59. balsa-0.0.4/setup.py +0 -26
  60. {balsa-0.0.4 → balsa-0.26.1}/balsa.egg-info/dependency_links.txt +0 -0
  61. {balsa-0.0.4 → balsa-0.26.1}/balsa.egg-info/top_level.txt +0 -0
@@ -0,0 +1,7 @@
1
+ [run]
2
+ # measure the balsa package only (not the tests, not the venv)
3
+ source = balsa
4
+ branch = True
5
+
6
+ [report]
7
+ show_missing = True
balsa-0.26.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 James Abel
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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 James Abel
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,5 @@
1
+ # Extra files for the sdist, on top of what setuptools includes by default (the balsa package, pyproject.toml, the
2
+ # readme and the license files): the test suite and what is needed to run it.
3
+ graft test_balsa
4
+ include pytest.ini .coveragerc requirements-dev.txt
5
+ global-exclude __pycache__ *.py[cod]
balsa-0.26.1/PKG-INFO ADDED
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: balsa
3
+ Version: 0.26.1
4
+ Summary: logging utility
5
+ Author-email: James Abel <j@abel.co>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jamesabel/balsa
8
+ Project-URL: Documentation, https://balsa.readthedocs.io/
9
+ Keywords: logging,utility
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: System :: Logging
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/x-rst
21
+ License-File: LICENSE
22
+ License-File: LICENSE.txt
23
+ Requires-Dist: appdirs
24
+ Requires-Dist: attrs
25
+ Requires-Dist: mttkinter
26
+ Requires-Dist: python-dateutil
27
+ Requires-Dist: yasf
28
+ Requires-Dist: tobool
29
+ Dynamic: license-file
30
+
31
+ .. this file is kept in the docs\source directory and COPIED to the project root directory.
32
+ .. DO NOT edit the copy in the project root directory.
33
+
34
+ balsa (logging utility)
35
+ =======================
36
+
37
+ .. image:: https://github.com/jamesabel/balsa/actions/workflows/ci.yml/badge.svg?branch=main
38
+ :target: https://github.com/jamesabel/balsa/actions/workflows/ci.yml
39
+ :alt: CI
40
+
41
+ .. image:: https://codecov.io/gh/jamesabel/balsa/branch/main/graph/badge.svg
42
+ :target: https://codecov.io/gh/jamesabel/balsa
43
+ :alt: Code coverage
44
+
45
+ .. image:: https://img.shields.io/pypi/v/balsa
46
+ :target: https://pypi.org/project/balsa/
47
+ :alt: PyPI version
48
+
49
+ .. image:: https://img.shields.io/pypi/pyversions/balsa
50
+ :target: https://pypi.org/project/balsa/
51
+ :alt: Supported Python versions
52
+
53
+ .. image:: https://img.shields.io/pypi/dm/balsa
54
+ :target: https://pypi.org/project/balsa/
55
+ :alt: PyPI downloads per month
56
+
57
+ .. image:: https://readthedocs.org/projects/balsa/badge/?version=latest
58
+ :target: https://balsa.readthedocs.io/en/latest/
59
+ :alt: Documentation status
60
+
61
+ .. image:: https://img.shields.io/pypi/l/balsa
62
+ :target: https://github.com/jamesabel/balsa/blob/main/LICENSE
63
+ :alt: License
64
+
65
+ Simple to use package that sets up Python logging. With just a few lines of code get well formatted logging to the
66
+ console, log file, popup windows and exception services.
67
+
68
+ Here is a short `Presentation on Balsa <https://www.abel.co/balsa_lightening_talk.pdf>`_.
69
+
70
+ Installation
71
+ ============
72
+
73
+ .. code-block:: console
74
+
75
+ pip install balsa
76
+
77
+ Major Features
78
+ ==============
79
+ - Simple to use. Add full-featured Python logging in just a few lines of code.
80
+ - Sane default log levels. Single `verbose` flag. (All levels can be overridden if desired, e.g. `console_log_level`.)
81
+ - Both console (stdout) and GUI (popup window) support.
82
+ - Log file support. Uses `appdirs` for log file paths.
83
+ - Structured logging via `yasf.sf()` (optional - you can still use simple strings).
84
+ - `Sentry <https://sentry.io/>`_ support. Just provide your `Sentry DSN <https://docs.sentry.io/concepts/key-terms/dsn-explainer/>`_.
85
+ Set the `BALSA_DEV` environment variable to keep development-time errors out of Sentry.
86
+ - `Sentry structured logs <https://docs.sentry.io/platforms/python/logs/>`_ support. Set `use_sentry_logs` to send log records to
87
+ Sentry as searchable, first-class log entries (requires sentry-sdk 2.35+).
88
+ - Informative log message formatting (or you can change it if you like).
89
+ - ISO 8601 timestamp format (with fractional seconds).
90
+ - Cross platform (Windows, Linux, macOS). Pure Python.
91
+ - Multiprocessing support.
92
+ - `AWS CloudWatch logs <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html>`_ support.
93
+ Structured logs enable `CloudWatch Logs Insights`.
94
+ - Optional error callback, e.g. to notify the user or exit on any error.
95
+ - In-memory buffer of recent log lines via `Balsa.get_string_list()`.
96
+
97
+ Simple Example
98
+ ==============
99
+
100
+ .. code:: python
101
+
102
+ from balsa import get_logger, Balsa
103
+
104
+ application_name = 'example'
105
+
106
+ log = get_logger(application_name)
107
+
108
+
109
+ def main():
110
+ balsa = Balsa(application_name, 'james abel')
111
+ balsa.init_logger()
112
+ log.error('my error example')
113
+
114
+
115
+ if __name__ == '__main__':
116
+ main()
117
+
118
+
119
+ This will yield output of this form:
120
+
121
+ .. code-block:: console
122
+
123
+ 2021-10-24T10:49:04.150790-07:00 - example - MainProcess - balsa_simple_example.py - 12 - main - ERROR - my error example
124
+
125
+ More examples are in the `examples <https://github.com/jamesabel/balsa/tree/main/examples>`_ directory.
126
+
127
+ Where did the name come from?
128
+ =============================
129
+ Balsa lumber is very soft and light, with a coarse, open grain.
130
+ The Balsa package is light weight, malleable, and open source.
@@ -0,0 +1,11 @@
1
+ from yasf import sf, structured_sentinel, convert_serializable_special_cases # provide these via yasf for legacy (remove eventually)
2
+ from .__version__ import __title__, __application_name__, __version__, __download_url__, __url__
3
+ from .__version__ import __author_email__, __author__, __copyright__, __description__, __license__
4
+ from .get_logger import get_logger
5
+ from .formatter import BalsaFormatter
6
+ from .handlers import HandlerType, BalsaNullHandler, BalsaStringListHandler
7
+ from .guihandler import DialogBoxHandler, tkinter_present
8
+ from .balsa import Balsa, verbose_arg_string, delete_existing_arg_string, log_dir_arg_string, balsa_dev_env_var, balsa_clone
9
+ from .balsa import get_global_balsa, get_global_config
10
+ from .structured import BalsaRecord, balsa_log_regex
11
+ from .balsa import traceback_string
@@ -0,0 +1,10 @@
1
+ __title__ = "balsa"
2
+ __application_name__ = __title__
3
+ __description__ = "logging utility"
4
+ __url__ = "https://github.com/jamesabel/balsa"
5
+ __download_url__ = "https://github.com/jamesabel/balsa/archive/master.zip"
6
+ __version__ = "0.26.1"
7
+ __author__ = "James Abel"
8
+ __author_email__ = "j@abel.co"
9
+ __license__ = "MIT"
10
+ __copyright__ = "Copyright 2018-2022 James Abel"
@@ -0,0 +1,86 @@
1
+ import logging
2
+ import json
3
+ from functools import lru_cache
4
+ import getpass
5
+ import platform
6
+
7
+ from yasf import sf_separate
8
+
9
+ log = logging.getLogger(__name__)
10
+
11
+
12
+ @lru_cache()
13
+ def get_user_name() -> str:
14
+ return getpass.getuser()
15
+
16
+
17
+ @lru_cache()
18
+ def get_computer_name() -> str:
19
+ return platform.node()
20
+
21
+
22
+ try:
23
+ # user may or may not use AWS CloudWatch logs
24
+
25
+ from awsimple import LogsAccess
26
+
27
+ awsimple_exists = True
28
+
29
+ except ImportError:
30
+
31
+ awsimple_exists = False
32
+
33
+ if awsimple_exists:
34
+
35
+ class AWSCloudWatchLogHandler(logging.NullHandler):
36
+ """
37
+ Send logs to AWS CloudWatch logs.
38
+ """
39
+
40
+ def __init__(self, log_group: str, **kwargs):
41
+ """
42
+ Init the AWS CloudWatch logs handler
43
+ :param log_group: AWS log group name
44
+ :param kwargs: AWS credentials (passed to boto3 via AWSimple). e.g. profile name or key pairs.
45
+ """
46
+ self.log_group = log_group
47
+ self.aws_kwargs = kwargs
48
+ self.logs_access = None # created lazily on first use, then reused (avoids creating a new boto3 session for every log record)
49
+ super().__init__()
50
+
51
+ def handle(self, record):
52
+ try:
53
+ args_json, kwargs_json = sf_separate(record.getMessage())
54
+ if kwargs_json is None:
55
+ put_dict = {}
56
+ else:
57
+ put_dict = json.loads(kwargs_json)
58
+ if args_json is not None and len(args_json) > 0:
59
+ put_dict["message"] = args_json
60
+
61
+ for attribute in ["created", "filename", "funcName", "levelname", "lineno", "module", "name", "pathname", "process", "thread", "threadName", "processName"]:
62
+ if attribute in put_dict:
63
+ attribute = f"_{attribute}"
64
+ put_dict[attribute] = getattr(record, attribute)
65
+
66
+ put_dict["system_user_name"] = get_user_name()
67
+ put_dict["system_computer_name"] = get_computer_name()
68
+
69
+ put_string = json.dumps(put_dict)
70
+
71
+ if self.logs_access is None:
72
+ self.logs_access = LogsAccess(self.log_group, **self.aws_kwargs)
73
+ self.logs_access.put(put_string)
74
+ except Exception:
75
+ # a cloud logging failure (e.g. a network error) must not raise out of the user's log call
76
+ self.handleError(record)
77
+
78
+ else:
79
+
80
+ # mypy will complain that AWSCloudWatchLogHandler is already defined ...
81
+
82
+ class AWSCloudWatchLogHandler(logging.NullHandler): # type: ignore
83
+ # dummy so we don't get an import error
84
+ def __init__(self, log_group: str, **kwargs):
85
+ log.error("AWS CloudWatch enabled but awsimple not installed")
86
+ super().__init__()