From 5ebfb82cfa04f640c5216047c92744516d29b338 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Thu, 30 Apr 2020 23:53:11 +0200 Subject: [PATCH] Fixed #1 - general setup --- .gitignore | 4 ++++ LICENSE.txt | 21 +++++++++++++++++++ PythonLibs/DefaultLogger.py | 42 +++++++++++++++++++++++++++++++++++++ PythonLibs/__init__.py | 1 + README.md | 3 +++ setup.cfg | 2 ++ setup.py | 25 ++++++++++++++++++++++ 7 files changed, 98 insertions(+) create mode 100644 LICENSE.txt create mode 100644 PythonLibs/DefaultLogger.py create mode 100644 PythonLibs/__init__.py create mode 100644 README.md create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index e69de29..c46d3a3 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,4 @@ +/dist/ +/MANIFEST +/build/ +/PythonLibs.egg-info/ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..63b4b68 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/PythonLibs/DefaultLogger.py b/PythonLibs/DefaultLogger.py new file mode 100644 index 0000000..3681b52 --- /dev/null +++ b/PythonLibs/DefaultLogger.py @@ -0,0 +1,42 @@ +import logging +import sys + + +class DefaultLogger: + DEFAULT_LOG_FORMAT = '[%(levelname)-7s] - %(asctime)s - %(module)s.%(funcName)s:%(lineno)d: %(message)s' + DEFAULT_DATE_FORMAT = '%Y-%m-%d %H:%M:%S' + + @classmethod + def create_logger(cls, appName: str, logLevel=logging.DEBUG, logFormat=None, dateFormat=None) -> logging.Logger: + logger = logging.getLogger(appName) + return cls.configure_logger(logger, logLevel, logFormat, dateFormat) + + @classmethod + def configure_logger(cls, logger: logging.Logger, + logLevel=logging.DEBUG, + logFormat=None, + dateFormat=None) -> logging.Logger: + logFormatter = cls.__create_formatter(logFormat, dateFormat) + + logger.setLevel(logLevel) + + outHandler = logging.StreamHandler(sys.stdout) + outHandler.setFormatter(logFormatter) + outHandler.setLevel(logging.DEBUG) + outHandler.addFilter(lambda record: record.levelno <= logging.INFO) + logger.addHandler(outHandler) + + errHandler = logging.StreamHandler(sys.stderr) + errHandler.setFormatter(logFormatter) + errHandler.setLevel(logging.WARNING) + logger.addHandler(errHandler) + return logger + + @classmethod + def __create_formatter(cls, logFormat=None, dateFormat=None) -> logging.Formatter: + if logFormat is None: + logFormat = cls.DEFAULT_LOG_FORMAT + if dateFormat is None: + dateFormat = cls.DEFAULT_DATE_FORMAT + + return logging.Formatter(fmt=logFormat, datefmt=dateFormat) diff --git a/PythonLibs/__init__.py b/PythonLibs/__init__.py new file mode 100644 index 0000000..9f0fa13 --- /dev/null +++ b/PythonLibs/__init__.py @@ -0,0 +1 @@ +from PythonLibs.DefaultLogger import DefaultLogger diff --git a/README.md b/README.md new file mode 100644 index 0000000..72a78af --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# PythonLibs + +Useful python classes. \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7da1909 --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +from setuptools import setup + +setup( + name='PythonLibs', + packages=['PythonLibs'], + version='1.0.0', + license='MIT', + description='Useful python classes', + author='TheCodeLabs', + author_email='spam@thecodelabs.de', + url='https://thecodelabs.de/TheCodeLabs/PythonLibs', + keywords=[], + install_requires=[ + ], + setup_requires=[ + 'wheel' + ], + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Build Tools', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3.7' + ] +) -- GitLab