EasyLoggerAJM 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.
- EasyLoggerAJM-0.1/EasyLoggerAJM/EasyLoggerAJM.py +107 -0
- EasyLoggerAJM-0.1/EasyLoggerAJM/__init__.py +1 -0
- EasyLoggerAJM-0.1/EasyLoggerAJM.egg-info/PKG-INFO +11 -0
- EasyLoggerAJM-0.1/EasyLoggerAJM.egg-info/SOURCES.txt +10 -0
- EasyLoggerAJM-0.1/EasyLoggerAJM.egg-info/dependency_links.txt +1 -0
- EasyLoggerAJM-0.1/EasyLoggerAJM.egg-info/top_level.txt +1 -0
- EasyLoggerAJM-0.1/LICENSE.txt +17 -0
- EasyLoggerAJM-0.1/PKG-INFO +11 -0
- EasyLoggerAJM-0.1/README.md +9 -0
- EasyLoggerAJM-0.1/setup.cfg +7 -0
- EasyLoggerAJM-0.1/setup.py +14 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
EasyLoggerAJM.py
|
|
3
|
+
|
|
4
|
+
logger with already set up generalized file handlers
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
import logging
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from os import makedirs
|
|
10
|
+
from os.path import join, isdir
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EasyLogger:
|
|
14
|
+
def __init__(self, project_name=None, root_log_location="../logs",
|
|
15
|
+
chosen_format='%(asctime)s | %(name)s | %(levelname)s | %(message)s', logger=None):
|
|
16
|
+
|
|
17
|
+
self._project_name = project_name
|
|
18
|
+
self._root_log_location = root_log_location
|
|
19
|
+
self._inner_log_fstructure = None
|
|
20
|
+
self._log_location = None
|
|
21
|
+
|
|
22
|
+
self.timestamp = datetime.now().isoformat(timespec='minutes').replace(':',
|
|
23
|
+
'') # datetime.now().date().isoformat()
|
|
24
|
+
self.formatter = logging.Formatter(chosen_format)
|
|
25
|
+
self.logger_levels = ["DEBUG", "INFO", "ERROR"]
|
|
26
|
+
if not logger:
|
|
27
|
+
# Create a logger with a specified name and make sure propagate is True
|
|
28
|
+
self.logger = logging.getLogger('logger')
|
|
29
|
+
else:
|
|
30
|
+
self.logger: logging.getLogger = logger
|
|
31
|
+
self.logger.propagate = True
|
|
32
|
+
|
|
33
|
+
self.make_file_handlers()
|
|
34
|
+
|
|
35
|
+
# set the logger level back to DEBUG, so it handles all messages
|
|
36
|
+
self.logger.setLevel(10)
|
|
37
|
+
self.logger.info(f"Starting {project_name} with the following FileHandlers:"
|
|
38
|
+
f"{self.logger.handlers[0]}"
|
|
39
|
+
f"{self.logger.handlers[1]}"
|
|
40
|
+
f"{self.logger.handlers[2]}")
|
|
41
|
+
# print("logger initialized")
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def UseLogger(cls, **kwargs):
|
|
45
|
+
return cls(**kwargs, logger=logging.getLogger('logger'))
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def project_name(self):
|
|
49
|
+
return self._project_name
|
|
50
|
+
|
|
51
|
+
@project_name.getter
|
|
52
|
+
def project_name(self):
|
|
53
|
+
if self._project_name:
|
|
54
|
+
pass
|
|
55
|
+
else:
|
|
56
|
+
self._project_name = __file__.split('\\')[-1].split(".")[0]
|
|
57
|
+
|
|
58
|
+
return self._project_name
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def inner_log_fstructure(self):
|
|
62
|
+
return self._inner_log_fstructure
|
|
63
|
+
|
|
64
|
+
@inner_log_fstructure.getter
|
|
65
|
+
def inner_log_fstructure(self):
|
|
66
|
+
self._inner_log_fstructure = "{}/{}".format(datetime.now().date().isoformat(),
|
|
67
|
+
''.join(
|
|
68
|
+
datetime.now().time().isoformat().split(
|
|
69
|
+
'.')[0].split(":")[:-1]))
|
|
70
|
+
return self._inner_log_fstructure
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def log_location(self):
|
|
74
|
+
return self._log_location
|
|
75
|
+
|
|
76
|
+
@log_location.getter
|
|
77
|
+
def log_location(self):
|
|
78
|
+
self._log_location = join(self._root_log_location, self.inner_log_fstructure)
|
|
79
|
+
if isdir(self._log_location):
|
|
80
|
+
pass
|
|
81
|
+
else:
|
|
82
|
+
makedirs(self._log_location)
|
|
83
|
+
return self._log_location
|
|
84
|
+
|
|
85
|
+
def make_file_handlers(self):
|
|
86
|
+
""" Add three filehandlers to the logger then set the log level to debug.
|
|
87
|
+
This way all messages will be sorted into their appropriate spots"""
|
|
88
|
+
for lvl in self.logger_levels:
|
|
89
|
+
self.logger.setLevel(lvl)
|
|
90
|
+
if self.logger.level == 10:
|
|
91
|
+
level_string = "DEBUG"
|
|
92
|
+
elif self.logger.level == 20:
|
|
93
|
+
level_string = "INFO"
|
|
94
|
+
elif self.logger.level == 40:
|
|
95
|
+
level_string = "ERROR"
|
|
96
|
+
else:
|
|
97
|
+
print("other logger level detected, defaulting to DEBUG")
|
|
98
|
+
level_string = "DEBUG"
|
|
99
|
+
log_path = join(self.log_location, '{}-{}-{}.log'.format(level_string, self.project_name, self.timestamp))
|
|
100
|
+
|
|
101
|
+
# Create a file handler for the logger, and specify the log file location
|
|
102
|
+
file_handler = logging.FileHandler(log_path)
|
|
103
|
+
# Set the logging format for the file handler
|
|
104
|
+
file_handler.setFormatter(self.formatter)
|
|
105
|
+
file_handler.setLevel(self.logger.level)
|
|
106
|
+
# Add the file handlers to the loggers
|
|
107
|
+
self.logger.addHandler(file_handler)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from EasyLoggerAJM.EasyLoggerAJM import EasyLogger
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: EasyLoggerAJM
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: logger with already set up generalized file handlers
|
|
5
|
+
Home-page: https://github.com/amcsparron2793-Water/EasyLoggerAJM
|
|
6
|
+
Download-URL: https://github.com/amcsparron2793-Water/EasyLoggerAJM/archive/refs/tags/0.1.tar.gz
|
|
7
|
+
Author: Amcsparron
|
|
8
|
+
Author-email: amcsparron@albanyny.gov
|
|
9
|
+
License: MIT License
|
|
10
|
+
Keywords: logging
|
|
11
|
+
License-File: LICENSE.txt
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
setup.cfg
|
|
4
|
+
setup.py
|
|
5
|
+
EasyLoggerAJM/EasyLoggerAJM.py
|
|
6
|
+
EasyLoggerAJM/__init__.py
|
|
7
|
+
EasyLoggerAJM.egg-info/PKG-INFO
|
|
8
|
+
EasyLoggerAJM.egg-info/SOURCES.txt
|
|
9
|
+
EasyLoggerAJM.egg-info/dependency_links.txt
|
|
10
|
+
EasyLoggerAJM.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
EasyLoggerAJM
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2018 Andrew McSparron
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: EasyLoggerAJM
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: logger with already set up generalized file handlers
|
|
5
|
+
Home-page: https://github.com/amcsparron2793-Water/EasyLoggerAJM
|
|
6
|
+
Download-URL: https://github.com/amcsparron2793-Water/EasyLoggerAJM/archive/refs/tags/0.1.tar.gz
|
|
7
|
+
Author: Amcsparron
|
|
8
|
+
Author-email: amcsparron@albanyny.gov
|
|
9
|
+
License: MIT License
|
|
10
|
+
Keywords: logging
|
|
11
|
+
License-File: LICENSE.txt
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='EasyLoggerAJM',
|
|
5
|
+
version='0.1',
|
|
6
|
+
packages=['EasyLoggerAJM'],
|
|
7
|
+
url='https://github.com/amcsparron2793-Water/EasyLoggerAJM',
|
|
8
|
+
download_url='https://github.com/amcsparron2793-Water/EasyLoggerAJM/archive/refs/tags/0.1.tar.gz',
|
|
9
|
+
keywords=['logging'],
|
|
10
|
+
license='MIT License',
|
|
11
|
+
author='Amcsparron',
|
|
12
|
+
author_email='amcsparron@albanyny.gov',
|
|
13
|
+
description='logger with already set up generalized file handlers'
|
|
14
|
+
)
|