inspy-logger 3.0.3__tar.gz → 3.1.0.dev1__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.
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/PKG-INFO +7 -5
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/Scripts/main.py +19 -21
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/__about__.py +0 -1
- inspy_logger-3.1.0.dev1/inspy_logger/__init__.py +135 -0
- inspy_logger-3.1.0.dev1/inspy_logger/common/__init__.py +78 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/common/meta.py +7 -0
- inspy_logger-3.1.0.dev1/inspy_logger/config/__init__.py +18 -0
- inspy_logger-3.1.0.dev1/inspy_logger/config/dirs.py +134 -0
- inspy_logger-3.1.0.dev1/inspy_logger/config/levels.py +29 -0
- inspy_logger-3.1.0.dev1/inspy_logger/constants.py +30 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/engine/__init__.py +241 -36
- inspy_logger-3.1.0.dev1/inspy_logger/engine/errors.py +49 -0
- inspy_logger-3.1.0.dev1/inspy_logger/helpers/__init__.py +542 -0
- inspy_logger-3.1.0.dev1/inspy_logger/helpers/decorators.py +261 -0
- inspy_logger-3.1.0.dev1/inspy_logger/helpers/descriptors.py +270 -0
- inspy_logger-3.1.0.dev1/inspy_logger/system/__init__.py +47 -0
- inspy_logger-3.1.0.dev1/inspy_logger/system/linux.py +36 -0
- inspy_logger-3.1.0.dev1/inspy_logger/system/mac_os.py +23 -0
- inspy_logger-3.1.0.dev1/inspy_logger/system/win32.py +50 -0
- inspy_logger-3.1.0.dev1/inspy_logger/version/VERSION.txt +1 -0
- inspy_logger-3.1.0.dev1/inspy_logger/version/__init__.py +495 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/pyproject.toml +12 -6
- inspy_logger-3.0.3/inspy_logger/__init__.py +0 -84
- inspy_logger-3.0.3/inspy_logger/common/__init__.py +0 -36
- inspy_logger-3.0.3/inspy_logger/common/dirs.py +0 -2
- inspy_logger-3.0.3/inspy_logger/helpers/__init__.py +0 -246
- inspy_logger-3.0.3/inspy_logger/helpers/decorators.py +0 -85
- inspy_logger-3.0.3/inspy_logger/version.py +0 -240
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/LICENSE.md +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/README.md +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/engine/handlers.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/errors/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/base_classes.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/command_line/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/debug/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/debug/environment.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/debug/system/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/debug/system/processor/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/debug/system/winx/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/network.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/helpers/units.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/manifest.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/tool/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/tool/config/__init__.py +0 -0
- {inspy_logger-3.0.3 → inspy_logger-3.1.0.dev1}/inspy_logger/tool/config/arguments/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: inspy-logger
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.1.0.dev1
|
|
4
4
|
Summary: Colorable, scalable logger for CLI
|
|
5
5
|
Home-page: https://github.com/Inspyre-Softworks/inSPy-Logger
|
|
6
6
|
License: MIT
|
|
@@ -26,11 +26,13 @@ Classifier: Topic :: System :: Logging
|
|
|
26
26
|
Classifier: Topic :: Utilities
|
|
27
27
|
Requires-Dist: appdirs (>=1.4.4,<2.0.0)
|
|
28
28
|
Requires-Dist: colorama (>=0.4.6,<0.5.0)
|
|
29
|
-
Requires-Dist: colorlog (>=6.
|
|
29
|
+
Requires-Dist: colorlog (>=6.8.2,<7.0.0)
|
|
30
30
|
Requires-Dist: humanize (>=4.4.0,<5.0.0)
|
|
31
|
-
Requires-Dist: luddite (>=1.0.
|
|
32
|
-
Requires-Dist: packaging (>=
|
|
33
|
-
Requires-Dist:
|
|
31
|
+
Requires-Dist: luddite (>=1.0.4,<2.0.0)
|
|
32
|
+
Requires-Dist: packaging (>=24.0,<25.0)
|
|
33
|
+
Requires-Dist: platformdirs (>=4.2.0,<5.0.0)
|
|
34
|
+
Requires-Dist: pypattyrn (>=1.2,<2.0)
|
|
35
|
+
Requires-Dist: python-box (>=7.1.1,<8.0.0)
|
|
34
36
|
Requires-Dist: requests (>=2.28.1,<3.0.0)
|
|
35
37
|
Requires-Dist: rich (>=13.7.0,<14.0.0)
|
|
36
38
|
Requires-Dist: setuptools-autover (>=1.0.2,<2.0.0)
|
|
@@ -16,6 +16,8 @@ from argparse import ArgumentParser
|
|
|
16
16
|
from inspy_logger.helpers.debug.environment import fetch_system_info
|
|
17
17
|
from inspy_logger.version import parse_version, PyPiVersionInfo
|
|
18
18
|
|
|
19
|
+
|
|
20
|
+
|
|
19
21
|
# ---- SET UP PARSER --------------------------------
|
|
20
22
|
|
|
21
23
|
parser = ArgumentParser('inspy-logger-version', description='Displays version information for inspy-logger.')
|
|
@@ -37,7 +39,7 @@ update_parser.add_argument('-p', '--pre-release', action='store_true', help='Whe
|
|
|
37
39
|
debug_parser = subparsers.add_parser('debug', help='Fetches a collection of environment information to help debug inspy-logger.')
|
|
38
40
|
|
|
39
41
|
debug_parser.add_argument('-C', '--copy-to-clipboard', action='store_true', help='Copies the debug information to the clipboard.')
|
|
40
|
-
debug_parser.add_argument('-P', '--print', action='store_true', help='Prints the debug information to the console.'
|
|
42
|
+
debug_parser.add_argument('-P', '--print', action='store_true', help='Prints the debug information to the console.')
|
|
41
43
|
|
|
42
44
|
# ---- FORMAT FLAGS --------------------------------
|
|
43
45
|
|
|
@@ -60,39 +62,35 @@ else:
|
|
|
60
62
|
INCLUDE_PRE_RELEASE_FOR_UPDATE_CHECK = False
|
|
61
63
|
|
|
62
64
|
|
|
65
|
+
def debug(args = parsed_args):
|
|
66
|
+
if args.markdown:
|
|
67
|
+
fmt = 'markdown'
|
|
68
|
+
elif args.json:
|
|
69
|
+
fmt = 'json'
|
|
70
|
+
else:
|
|
71
|
+
fmt = 'text'
|
|
72
|
+
|
|
73
|
+
fetch_system_info(copy_to_clipboard=args.copy_to_clipboard, format_type=fmt, print_to_console=args.print)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
63
77
|
def main():
|
|
64
78
|
|
|
65
|
-
version = PyPiVersionInfo()
|
|
79
|
+
version = PyPiVersionInfo(INCLUDE_PRE_RELEASE_FOR_UPDATE_CHECK)
|
|
66
80
|
|
|
67
81
|
ACTIONS = {
|
|
68
82
|
'default': version.print_version_info,
|
|
69
83
|
'update': version.update,
|
|
70
|
-
'debug':
|
|
84
|
+
'debug': debug,
|
|
71
85
|
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
if parsed_args.subcommand is None:
|
|
75
89
|
parsed_args.subcommand = 'default'
|
|
76
90
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
parsed_args.markdown
|
|
81
|
-
or not parsed_args.json
|
|
82
|
-
and not parsed_args.text
|
|
83
|
-
):
|
|
84
|
-
fmt = 'markdown'
|
|
85
|
-
elif parsed_args.json:
|
|
86
|
-
fmt = 'json'
|
|
87
|
-
else:
|
|
88
|
-
fmt = 'text'
|
|
89
|
-
|
|
90
|
-
fetch_system_info(copy_to_clipboard=parsed_args.copy_to_clipboard, format_type=fmt, print_to_console=parsed_args.print)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
# Run the action.
|
|
92
|
+
ACTIONS[parsed_args.subcommand]()
|
|
94
93
|
|
|
95
|
-
return parsed_args
|
|
96
94
|
|
|
97
95
|
if __name__ == '__main__':
|
|
98
96
|
main()
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import contextlib
|
|
3
|
+
import sys
|
|
4
|
+
import inspect
|
|
5
|
+
import logging
|
|
6
|
+
from pypattyrn.behavioral.null import Null
|
|
7
|
+
from inspy_logger.common import PROG_NAME as ISL_PROG_NAME, DEFAULT_LOGGING_LEVEL, DEFAULT_LOG_FILE_PATH, LEVELS
|
|
8
|
+
from inspy_logger.helpers import find_variable_in_call_stack, check_preemptive_level_set, find_argument_parser, determine_start_block, determine_level
|
|
9
|
+
|
|
10
|
+
from inspy_logger.helpers import (
|
|
11
|
+
translate_to_logging_level,
|
|
12
|
+
clean_module_name,
|
|
13
|
+
CustomFormatter,
|
|
14
|
+
determine_client_prog_name,
|
|
15
|
+
determine_log_file_path
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# Existing log record factory
|
|
19
|
+
old_factory = logging.getLogRecordFactory()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def record_factory(*args, **kwargs):
|
|
23
|
+
record = old_factory(*args, **kwargs)
|
|
24
|
+
# Set the file_name attribute to the name of the file where the log is called
|
|
25
|
+
frame = inspect.stack()[1]
|
|
26
|
+
record.file_name = frame.filename
|
|
27
|
+
return record
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
logging.setLogRecordFactory(record_factory)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
from inspy_logger.engine import Logger
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"clean_module_name",
|
|
37
|
+
"CustomFormatter",
|
|
38
|
+
"DEFAULT_LOGGING_LEVEL",
|
|
39
|
+
"determine_level",
|
|
40
|
+
"InspyLogger",
|
|
41
|
+
"LOG_DEVICE",
|
|
42
|
+
"Logger",
|
|
43
|
+
"ISL_PROG_NAME",
|
|
44
|
+
"translate_to_logging_level",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
BLOCKED = determine_start_block()
|
|
48
|
+
|
|
49
|
+
LOG_FILE = determine_log_file_path()
|
|
50
|
+
|
|
51
|
+
LOG_DEVICE = None if BLOCKED else Logger(ISL_PROG_NAME)
|
|
52
|
+
|
|
53
|
+
MODULE_OBJ = sys.modules[__name__]
|
|
54
|
+
|
|
55
|
+
CLIENT_PROG_NAME = determine_client_prog_name()
|
|
56
|
+
|
|
57
|
+
INIT_LOG_LEVEL = determine_level(CLIENT_PROG_NAME)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def start_logger(override_block=True):
|
|
61
|
+
"""
|
|
62
|
+
Starts the logger.
|
|
63
|
+
|
|
64
|
+
Parameters:
|
|
65
|
+
override_block (Union[bool, None], optional):
|
|
66
|
+
A flag to override the block on the logger. Defaults to True.
|
|
67
|
+
|
|
68
|
+
Note:
|
|
69
|
+
You only need to run this function if you have blocked the logger from starting automatically.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
global LOG_DEVICE
|
|
75
|
+
global CLIENT_PROG_NAME
|
|
76
|
+
global INIT_LOG_LEVEL
|
|
77
|
+
|
|
78
|
+
if not BLOCKED or override_block:
|
|
79
|
+
LOG_DEVICE = Logger(ISL_PROG_NAME)
|
|
80
|
+
LOG_DEVICE.set_level(INIT_LOG_LEVEL)
|
|
81
|
+
|
|
82
|
+
if CLIENT_PROG_NAME:
|
|
83
|
+
|
|
84
|
+
prog_logger = Logger(
|
|
85
|
+
CLIENT_PROG_NAME,
|
|
86
|
+
LOG_DEVICE.console_level,
|
|
87
|
+
LOG_DEVICE.file_level,
|
|
88
|
+
file_name=DEFAULT_LOG_FILE_PATH.name,
|
|
89
|
+
file_path=DEFAULT_LOG_FILE_PATH.parent
|
|
90
|
+
)
|
|
91
|
+
__all__.append('PROG_LOGGER')
|
|
92
|
+
|
|
93
|
+
LOG_DEVICE.replay_and_setup_handlers()
|
|
94
|
+
elif CLIENT_PROG_NAME:
|
|
95
|
+
prog_logger = Null()
|
|
96
|
+
|
|
97
|
+
with contextlib.suppress(NameError):
|
|
98
|
+
global PROG_LOGGER
|
|
99
|
+
|
|
100
|
+
PROG_LOGGER = prog_logger
|
|
101
|
+
|
|
102
|
+
if isinstance(PROG_LOGGER, Null):
|
|
103
|
+
from rich import print
|
|
104
|
+
print("The logger has been blocked from starting. To start the logger, run `start_logger()`.")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
InspyLogger = Logger
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _get_loggable():
|
|
111
|
+
from inspy_logger.helpers.base_classes import Loggable
|
|
112
|
+
import bisect
|
|
113
|
+
# Add the `Loggable` class to `__all__` in alphabetical order.
|
|
114
|
+
bisect.insort(__all__, 'Loggable')
|
|
115
|
+
|
|
116
|
+
return Loggable
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
Loggable = _get_loggable()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
start_logger(override_block=False)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
deprecation_warning_deliveries = 0
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def getLogger(*args, **kwargs):
|
|
129
|
+
global deprecation_warning_deliveries
|
|
130
|
+
|
|
131
|
+
if deprecation_warning_deliveries < 5:
|
|
132
|
+
LOG_DEVICE.warning('The `getLogger` function is deprecated. Use `InspyLogger` instead.')
|
|
133
|
+
deprecation_warning_deliveries += 1
|
|
134
|
+
|
|
135
|
+
return InspyLogger(*args, **kwargs)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the logging configuration and constants used within the inSPy-Logger project. It includes the mapping of log
|
|
3
|
+
levels, default settings, and the `InspyLogger` class which is a central part of the logging framework.
|
|
4
|
+
|
|
5
|
+
Constants:
|
|
6
|
+
PROG_NAME (str):
|
|
7
|
+
The program name, imported from the project's `__about__` module.
|
|
8
|
+
|
|
9
|
+
PROG_VERSION (str):
|
|
10
|
+
The program version, imported from the project's `__about__` module.
|
|
11
|
+
|
|
12
|
+
LEVEL_MAP (dict):
|
|
13
|
+
A dictionary mapping string representations of logging levels to their corresponding logging module constants.
|
|
14
|
+
|
|
15
|
+
LEVELS (list):
|
|
16
|
+
A list of available logging levels derived from `LEVEL_MAP`.
|
|
17
|
+
|
|
18
|
+
DEFAULT_LOGGING_LEVEL (logging level):
|
|
19
|
+
The default logging level used throughout the project.
|
|
20
|
+
|
|
21
|
+
DEFAULT_LOG_FILE_PATH (path):
|
|
22
|
+
The default path where log files are stored, defined in `inspy_logger.common.dirs`.
|
|
23
|
+
|
|
24
|
+
Classes:
|
|
25
|
+
InspyLogger:
|
|
26
|
+
A placeholder for the logging class used in the inSPy-Logger project.
|
|
27
|
+
|
|
28
|
+
Dependencies:
|
|
29
|
+
- logging:
|
|
30
|
+
Used to define the logging levels and to be used in the `InspyLogger` class for actual logging.
|
|
31
|
+
|
|
32
|
+
- inspy_logger.__about__:
|
|
33
|
+
Provides metadata like program name and version, which are used in logging for contextual information.
|
|
34
|
+
|
|
35
|
+
- inspy_logger.common.dirs:
|
|
36
|
+
Provides common directory paths used in the logger, including the default log file path.
|
|
37
|
+
|
|
38
|
+
Example Usage:
|
|
39
|
+
# This example shows how to access and use the constants defined in this module
|
|
40
|
+
>>> from inspy_logger.common.logging_config import DEFAULT_LOGGING_LEVEL, LEVEL_MAP
|
|
41
|
+
>>> print(DEFAULT_LOGGING_LEVEL)
|
|
42
|
+
DEBUG
|
|
43
|
+
>>> print(LEVEL_MAP['error'])
|
|
44
|
+
40
|
|
45
|
+
|
|
46
|
+
# Example of how `InspyLogger` might be used in the future (assuming further implementation)
|
|
47
|
+
>>> logger = InspyLogger()
|
|
48
|
+
>>> logger.log(level='error', message='This is an error message')
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
import logging
|
|
53
|
+
|
|
54
|
+
from inspy_logger.__about__ import __PROG__ as PROG_NAME, __VERSION__ as PROG_VERSION
|
|
55
|
+
from inspy_logger.config.dirs import DEFAULT_LOG_FILE_PATH
|
|
56
|
+
from inspy_logger.constants import LEVEL_MAP
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
"PROG_NAME",
|
|
60
|
+
"PROG_VERSION",
|
|
61
|
+
"LEVEL_MAP",
|
|
62
|
+
"LEVELS",
|
|
63
|
+
"DEFAULT_LOGGING_LEVEL",
|
|
64
|
+
"DEFAULT_LOG_FILE_PATH",
|
|
65
|
+
"InspyLogger"
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
LEVELS = list(LEVEL_MAP.values())
|
|
70
|
+
"""The list of level names."""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
DEFAULT_LOGGING_LEVEL = logging.DEBUG
|
|
74
|
+
"""The default logging level."""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class InspyLogger:
|
|
78
|
+
pass
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
__all__ = [
|
|
2
|
+
'SOFTWARE_ORG',
|
|
3
|
+
'SOFTWARE_ORG_URL',
|
|
2
4
|
'AUTHORS',
|
|
5
|
+
'PROG_NAME',
|
|
3
6
|
'RELEASE_MAP',
|
|
4
7
|
'URLS',
|
|
5
8
|
'VERSION'
|
|
6
9
|
]
|
|
7
10
|
|
|
11
|
+
PROG_NAME = 'inSPy-Logger'
|
|
12
|
+
|
|
8
13
|
URLS = dict(
|
|
9
14
|
developer_url='https://inspyre.tech',
|
|
10
15
|
docs_url='https://inspyre-toolbox.readthedocs.io/en/latest',
|
|
@@ -19,6 +24,8 @@ AUTHORS = [
|
|
|
19
24
|
]
|
|
20
25
|
"""The authors of the project."""
|
|
21
26
|
|
|
27
|
+
SOFTWARE_ORG, SOFTWARE_ORG_URL = AUTHORS[0]
|
|
28
|
+
|
|
22
29
|
RELEASE_MAP = {
|
|
23
30
|
'dev': 'Development Build',
|
|
24
31
|
'alpha': 'Alpha Build',
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
from platformdirs import user_log_path
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from inspy_logger.common.meta import *
|
|
4
|
+
from inspy_logger.helpers import (
|
|
5
|
+
find_valid_vars_in_call_stack,
|
|
6
|
+
VALID_LOG_FILE_VARS,
|
|
7
|
+
VALID_PROG_NAME_VARS,
|
|
8
|
+
determine_log_file_path,
|
|
9
|
+
determine_client_prog_name,
|
|
10
|
+
VALID_DEV_NAME_VARS
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from typing import Optional, Union
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
INSPY_LOGGER_LOG_DIR_PATH = user_log_path(
|
|
17
|
+
appname=PROG_NAME or find_valid_vars_in_call_stack(VALID_PROG_NAME_VARS),
|
|
18
|
+
appauthor=SOFTWARE_ORG,
|
|
19
|
+
ensure_exists=True
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
INSPY_LOGGER_LOG_FILE_NAME = 'app.log'
|
|
23
|
+
|
|
24
|
+
INSPY_LOGGER_LOG_FILE_PATH = INSPY_LOGGER_LOG_DIR_PATH.joinpath(INSPY_LOGGER_LOG_FILE_NAME)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# def get_log_file_path(
|
|
28
|
+
# log_file_path: Union[str, Path] = None,
|
|
29
|
+
# prog_name: str = None,
|
|
30
|
+
# dev_name: str = None
|
|
31
|
+
# ) -> Path:
|
|
32
|
+
# """
|
|
33
|
+
# Get the path to the log file.
|
|
34
|
+
#
|
|
35
|
+
# Parameters:
|
|
36
|
+
# log_file_path (str, Path, optional):
|
|
37
|
+
# The path to the log file.
|
|
38
|
+
#
|
|
39
|
+
# prog_name (str):
|
|
40
|
+
# The name of the program to be logged.
|
|
41
|
+
#
|
|
42
|
+
# dev_name (str):
|
|
43
|
+
# The name of the developer of the app to be logged.
|
|
44
|
+
#
|
|
45
|
+
# Note:
|
|
46
|
+
# The `log_file_name` is simply the name of the file to be logged to, not the full path.
|
|
47
|
+
#
|
|
48
|
+
# Returns:
|
|
49
|
+
# Path:
|
|
50
|
+
# The path to the log file.
|
|
51
|
+
# """
|
|
52
|
+
# print(f'Found log-file path: {FOUND_LOG_FILE_VARS}')
|
|
53
|
+
# log_file_path = log_file_path or FOUND_LOG_FILE_VARS
|
|
54
|
+
# log_file_path = Path(log_file_path) if log_file_path else None
|
|
55
|
+
#
|
|
56
|
+
# if not log_file_path:
|
|
57
|
+
# if not prog_name:
|
|
58
|
+
# prog_name = determine_client_prog_name()
|
|
59
|
+
# print(f'Found prog-name: {prog_name}')
|
|
60
|
+
# if prog_name and not dev_name:
|
|
61
|
+
# dev_name = find_valid_vars_in_call_stack(VALID_DEV_NAME_VARS.valid_vars)
|
|
62
|
+
#
|
|
63
|
+
# if dev_name:
|
|
64
|
+
# print(f'Found dev-name: {dev_name}')
|
|
65
|
+
#
|
|
66
|
+
#
|
|
67
|
+
#
|
|
68
|
+
#
|
|
69
|
+
# #if not log_file_path.suffix and log_file_path.is_dir() and INSPY_LOGGER_LOG_FILE_NAME:
|
|
70
|
+
# # log_file_path = log_file_path.joinpath(INSPY_LOGGER_LOG_FILE_NAME)
|
|
71
|
+
#
|
|
72
|
+
# if all(arg is None for arg in [
|
|
73
|
+
# log_file_path,
|
|
74
|
+
# prog_name,
|
|
75
|
+
# dev_name
|
|
76
|
+
# ]):
|
|
77
|
+
# return INSPY_LOGGER_LOG_FILE_PATH
|
|
78
|
+
#
|
|
79
|
+
# return log_file_path
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def get_log_file_path(
|
|
83
|
+
log_file_path: Union[str, Path] = None,
|
|
84
|
+
prog_name: str = None,
|
|
85
|
+
dev_name: str = None
|
|
86
|
+
) -> Path:
|
|
87
|
+
"""
|
|
88
|
+
Get the path to the log file.
|
|
89
|
+
|
|
90
|
+
Parameters:
|
|
91
|
+
log_file_path (str, Path, optional):
|
|
92
|
+
The path to the log file.
|
|
93
|
+
|
|
94
|
+
prog_name (str):
|
|
95
|
+
The name of the program to be logged.
|
|
96
|
+
|
|
97
|
+
dev_name (str):
|
|
98
|
+
The name of the developer of the app to be logged.
|
|
99
|
+
|
|
100
|
+
Note:
|
|
101
|
+
The `log_file_name` is simply the name of the file to be logged to, not the full path.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Path:
|
|
105
|
+
The path to the log file.
|
|
106
|
+
"""
|
|
107
|
+
log_file_path = Path(log_file_path) if isinstance(log_file_path, str) else log_file_path
|
|
108
|
+
|
|
109
|
+
if log_file_path:
|
|
110
|
+
return log_file_path
|
|
111
|
+
|
|
112
|
+
log_file_path = find_valid_vars_in_call_stack(VALID_LOG_FILE_VARS)
|
|
113
|
+
|
|
114
|
+
if log_file_path:
|
|
115
|
+
log_file_path = Path(log_file_path)
|
|
116
|
+
return log_file_path
|
|
117
|
+
|
|
118
|
+
if not prog_name:
|
|
119
|
+
prog_name = determine_client_prog_name()
|
|
120
|
+
|
|
121
|
+
if not dev_name and prog_name:
|
|
122
|
+
dev_name = find_valid_vars_in_call_stack(VALID_DEV_NAME_VARS.valid_vars)
|
|
123
|
+
|
|
124
|
+
if prog_name:
|
|
125
|
+
file_name = f"{prog_name}.log"
|
|
126
|
+
if dev_name:
|
|
127
|
+
log_file_path = Path(user_log_path(appname=prog_name, appauthor=dev_name, ensure_exists=True)).joinpath(file_name)
|
|
128
|
+
else:
|
|
129
|
+
log_file_path = INSPY_LOGGER_LOG_DIR_PATH.joinpath(file_name)
|
|
130
|
+
|
|
131
|
+
return log_file_path or INSPY_LOGGER_LOG_FILE_PATH
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
DEFAULT_LOG_FILE_PATH = get_log_file_path()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Author:
|
|
5
|
+
Inspyre Softworks
|
|
6
|
+
|
|
7
|
+
Project:
|
|
8
|
+
inSPy-Logger
|
|
9
|
+
|
|
10
|
+
File:
|
|
11
|
+
inspy_logger/config/levels.py
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Description:
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
LEVEL_MAP = {
|
|
22
|
+
'debug': logging.DEBUG,
|
|
23
|
+
'info': logging.INFO,
|
|
24
|
+
'warning': logging.WARNING,
|
|
25
|
+
'error': logging.ERROR,
|
|
26
|
+
'critical': logging.CRITICAL,
|
|
27
|
+
'fatal': logging.FATAL,
|
|
28
|
+
}
|
|
29
|
+
"""A mapping of level names to their corresponding logging levels."""
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Author:
|
|
5
|
+
Inspyre Softworks
|
|
6
|
+
|
|
7
|
+
Project:
|
|
8
|
+
inSPy-Logger
|
|
9
|
+
|
|
10
|
+
File:
|
|
11
|
+
inspy_logger/constants.py
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Description:
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
DEFAULT_LOGGING_LEVEL = logging.DEBUG
|
|
21
|
+
|
|
22
|
+
LEVEL_MAP = {
|
|
23
|
+
'debug': logging.DEBUG,
|
|
24
|
+
'info': logging.INFO,
|
|
25
|
+
'warning': logging.WARNING,
|
|
26
|
+
'error': logging.ERROR,
|
|
27
|
+
'critical': logging.CRITICAL,
|
|
28
|
+
'fatal': logging.FATAL,
|
|
29
|
+
}
|
|
30
|
+
"""A mapping of level names to their corresponding logging levels."""
|