wai.logging 0.0.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.
@@ -0,0 +1,8 @@
1
+ Changelog
2
+ =========
3
+
4
+ 0.0.1 (????-??-??)
5
+ ------------------
6
+
7
+ - initial release
8
+
@@ -0,0 +1 @@
1
+ Python library with helper methods for logging.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 University of Waikato - Data Mining
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,3 @@
1
+ include DESCRIPTION.rst
2
+ include CHANGES.rst
3
+ include LICENSE
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.1
2
+ Name: wai.logging
3
+ Version: 0.0.1
4
+ Summary: Python library with helper methods for logging.
5
+ Home-page: https://github.com/waikato-datamining/wai-logging
6
+ Author: Peter Reutemann
7
+ Author-email: fracpete@waikato.ac.nz
8
+ License: MIT
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Classifier: Programming Language :: Python :: 3
13
+ License-File: LICENSE
14
+
15
+ Python library with helper methods for logging.
16
+
17
+ Changelog
18
+ =========
19
+
20
+ 0.0.1 (????-??-??)
21
+ ------------------
22
+
23
+ - initial release
24
+
@@ -0,0 +1,10 @@
1
+ # wai-logging
2
+ Simple helper library for logging.
3
+
4
+ ## Methods
5
+
6
+ * `init_logging` - initializes the logging with a default level, which can be overridden with an environment variable
7
+ * `set_logging_level` - sets the logging level of a `logging.Logger` instance
8
+ * `str_to_logging_level` - turns a string logging level into a `logging` module one, used by `init_logging` and `set_logging_level`
9
+ * `add_logging_level` - adds an option for the logging level to an `argparse.ArgumentParser` instance
10
+ * `add_logger_name` - adds an option for a custom name for a logger to an `argparse.ArgumentParser` instance
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,38 @@
1
+ from setuptools import setup
2
+
3
+
4
+ def _read(f) -> bytes:
5
+ """
6
+ Reads in the content of the file.
7
+ :param f: the file to read
8
+ :type f: str
9
+ :return: the content
10
+ :rtype: str
11
+ """
12
+ return open(f, 'rb').read()
13
+
14
+
15
+ setup(
16
+ name="wai.logging",
17
+ description="Python library with helper methods for logging.",
18
+ long_description=(
19
+ _read('DESCRIPTION.rst') + b'\n' +
20
+ _read('CHANGES.rst')).decode('utf-8'),
21
+ url="https://github.com/waikato-datamining/wai-logging",
22
+ classifiers=[
23
+ 'Development Status :: 4 - Beta',
24
+ 'License :: OSI Approved :: MIT License',
25
+ 'Topic :: Scientific/Engineering :: Mathematics',
26
+ 'Programming Language :: Python :: 3',
27
+ ],
28
+ license='MIT',
29
+ package_dir={
30
+ '': 'src'
31
+ },
32
+ packages=[
33
+ "wai.logging",
34
+ ],
35
+ version="0.0.1",
36
+ author='Peter Reutemann',
37
+ author_email='fracpete@waikato.ac.nz',
38
+ )
@@ -0,0 +1,3 @@
1
+ from ._core import LOGGING_LEVELS, LOGGING_DEBUG, LOGGING_INFO, LOGGING_WARN, LOGGING_WARNING, LOGGING_ERROR, LOGGING_CRITICAL
2
+ from ._core import init_logging, set_logging_level, str_to_logging_level
3
+ from ._argparse import add_logging_level, add_logger_name
@@ -0,0 +1,41 @@
1
+ import argparse
2
+
3
+ from ._core import LOGGING_LEVELS, LOGGING_WARN
4
+
5
+
6
+ def add_logging_level(parser: argparse.ArgumentParser, short_opt: str = "-l", long_opt: str = "--logging_level",
7
+ help_str: str = None):
8
+ """
9
+ Adds an option for the logging level to the parser.
10
+
11
+ :param parser: the parser to append.
12
+ :type parser: argparse.ArgumentParser
13
+ :param short_opt: the short option flag to use (eg -l)
14
+ :type short_opt: str
15
+ :param long_opt: the long option flag to use (eg --logging_level)
16
+ :type long_opt: str
17
+ :param help_str: the help string to use
18
+ :type help_str: str
19
+ """
20
+ if help_str is None:
21
+ help_str = "The logging level to use."
22
+ parser.add_argument(short_opt, long_opt, choices=LOGGING_LEVELS, default=LOGGING_WARN, help=help_str)
23
+
24
+
25
+ def add_logger_name(parser: argparse.ArgumentParser, short_opt: str = "-N", long_opt: str = "--logger_name",
26
+ help_str: str = None):
27
+ """
28
+ Adds an option for the logger name to the parser.
29
+
30
+ :param parser: the parser to append.
31
+ :type parser: argparse.ArgumentParser
32
+ :param short_opt: the short option flag to use (eg -N)
33
+ :type short_opt: str
34
+ :param long_opt: the long option flag to use (eg --logger_name)
35
+ :type long_opt: str
36
+ :param help_str: the help string to use
37
+ :type help_str: str
38
+ """
39
+ if help_str is None:
40
+ help_str = "The custom name to use for the logger"
41
+ parser.add_argument(short_opt, long_opt, type=str, default=None, help=help_str, required=False)
@@ -0,0 +1,73 @@
1
+ import logging
2
+ import os
3
+
4
+
5
+ LOGGING_DEBUG = "DEBUG"
6
+ LOGGING_INFO = "INFO"
7
+ LOGGING_WARN = "WARN"
8
+ LOGGING_WARNING = "WARNING"
9
+ LOGGING_ERROR = "ERROR"
10
+ LOGGING_CRITICAL = "CRITICAL"
11
+ LOGGING_LEVELS = [
12
+ LOGGING_DEBUG,
13
+ LOGGING_INFO,
14
+ LOGGING_WARNING,
15
+ LOGGING_ERROR,
16
+ LOGGING_CRITICAL,
17
+ ]
18
+
19
+
20
+ def str_to_logging_level(level: str) -> int:
21
+ """
22
+ Turns a logging level string into the corresponding integer constant.
23
+
24
+ :param level: the level to convert
25
+ :type level: str
26
+ :return: the int level
27
+ :rtype: int
28
+ """
29
+ level = level.upper()
30
+ if level == LOGGING_WARN:
31
+ level = LOGGING_WARNING
32
+ if level not in LOGGING_LEVELS:
33
+ raise Exception("Invalid logging level (%s): %s" % ("|".join(LOGGING_LEVELS), level))
34
+ if level == LOGGING_CRITICAL:
35
+ return logging.CRITICAL
36
+ elif level == LOGGING_ERROR:
37
+ return logging.ERROR
38
+ elif level == LOGGING_WARNING:
39
+ return logging.WARNING
40
+ elif level == LOGGING_INFO:
41
+ return logging.INFO
42
+ elif level == LOGGING_DEBUG:
43
+ return logging.DEBUG
44
+ else:
45
+ raise Exception("Unhandled logging level: %s" % level)
46
+
47
+
48
+ def init_logging(default_level: str = LOGGING_WARNING, env_var: str = None):
49
+ """
50
+ Initializes the logging.
51
+
52
+ :param default_level: the default level to use
53
+ :type default_level: str
54
+ :param env_var: the environment variable to check for a level (overrides the default level), ignored if None
55
+ :type env_var: str
56
+ """
57
+ level = str_to_logging_level(default_level)
58
+ if env_var is not None:
59
+ if os.getenv(env_var) is not None:
60
+ level = str_to_logging_level(os.getenv(env_var))
61
+ logging.basicConfig(level=level)
62
+
63
+
64
+ def set_logging_level(logger: logging.Logger, level: str):
65
+ """
66
+ Sets the logging level of the logger.
67
+
68
+ :param logger: the logger to update
69
+ :type logger: logging.Logger
70
+ :param level: the level string, see LOGGING_LEVELS
71
+ :type level: str
72
+ """
73
+ logger.setLevel(str_to_logging_level(level))
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.1
2
+ Name: wai.logging
3
+ Version: 0.0.1
4
+ Summary: Python library with helper methods for logging.
5
+ Home-page: https://github.com/waikato-datamining/wai-logging
6
+ Author: Peter Reutemann
7
+ Author-email: fracpete@waikato.ac.nz
8
+ License: MIT
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Classifier: Programming Language :: Python :: 3
13
+ License-File: LICENSE
14
+
15
+ Python library with helper methods for logging.
16
+
17
+ Changelog
18
+ =========
19
+
20
+ 0.0.1 (????-??-??)
21
+ ------------------
22
+
23
+ - initial release
24
+
@@ -0,0 +1,13 @@
1
+ CHANGES.rst
2
+ DESCRIPTION.rst
3
+ LICENSE
4
+ MANIFEST.in
5
+ README.md
6
+ setup.py
7
+ src/wai.logging.egg-info/PKG-INFO
8
+ src/wai.logging.egg-info/SOURCES.txt
9
+ src/wai.logging.egg-info/dependency_links.txt
10
+ src/wai.logging.egg-info/top_level.txt
11
+ src/wai/logging/__init__.py
12
+ src/wai/logging/_argparse.py
13
+ src/wai/logging/_core.py