Skip to content

Commit

Permalink
Merge pull request #5 from tg4nd4lf/feature/project-structure-tryout
Browse files Browse the repository at this point in the history
Merge to main
  • Loading branch information
tg4nd4lf authored Aug 27, 2024
2 parents 13123ae + d8cef53 commit 82f0e82
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# log-wise

'log-wise ' is a Python library for a default logger, useable in all projects.
'log-wise ' is a Python library for a default logger, usable in all projects.

Credits: https://stackoverflow.com/a/56944256/3638629

## Install

- Use the 'setup.py'
- PyPi.org

## Build

#### Check all files are valid
`
twine check dist/*
`
#### Build
`
python setup.py sdist bdist_wheel
`
Expand Down
Empty file added logs/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
install_requires=[
'setuptools==69.1.1',
'utils==1.0.2',
'wheel==0.42.0'
'wheel==0.42.0',
'twine==5.0.0'
],
classifiers=[
'Intended Audience :: Developers',
Expand Down
28 changes: 15 additions & 13 deletions src/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,41 @@
import os
import logging
import datetime
from src.formatter import CustomFormatter
from time import ctime
from .formatter import CustomFormatter

__version__ = "0.2"
__version__ = "1.0"
__author__ = "klaus-moser"
__date__ = ctime(os.path.getmtime(__file__))


def configure_logger(filename: str = "my_app_") -> logging.Logger:
def configure_logger(filename: str = None) -> logging.Logger:
"""
Set up logger.
:return: Logger instance.
"""

# Create custom logger logging all five levels
# Create custom logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)

# Define format for logs
fmt = '%(asctime)s | %(levelname)8s | %(message)s'

# Create stdout handler for logging to the console (logs all five levels)
# Create stdout handler for logging to the console
stdout_handler = logging.StreamHandler()
stdout_handler.setLevel(logging.DEBUG)
stdout_handler.setLevel(logging.INFO)
stdout_handler.setFormatter(CustomFormatter(fmt))

# Create file handler for logging to a file (logs all five levels)
# Create file handler for logging to a file
today = datetime.date.today()

file_handler = logging.FileHandler(
filename=os.path.join(os.path.dirname(__file__), '{}_{}.log'.format(filename, today.strftime('%Y_%m_%d'))))
file_handler.setLevel(logging.DEBUG)
if filename is None:
filename = os.path.join(os.path.dirname(__file__), '{}_{}.log'.format("my_app_", today.strftime('%Y_%m_%d')))
else:
filename = '{}_{}.log'.format(filename, today.strftime('%Y_%m_%d'))

file_handler = logging.FileHandler(filename=filename)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter(fmt))

# Add both handlers to the logger
Expand Down

0 comments on commit 82f0e82

Please sign in to comment.