Custom logger for python using pre-defined logging conventions. This custom logger is mainly adapted from Alexandra Zaharia's custom logger. Blog Link: https://alexandra-zaharia.github.io/posts/custom-logger-in-python-for-stdout-and-or-file-log/
Download the project into your IDE environment. Install all required packages in the devt_requirement.txt file.
All logged messages are following the below format:
{Date Time} | {Log Level} | {File}:{Function} | {Log Message}
logger = Logger('logger_name', verbose=True, log_dir'log_path')
logger.debug('Debug Message')
This project uses pytest and coverage libraries for unit testing and coverage report. To run testing, run python -m pytest at the root folder of the project. It will recursively search for all functions with test_ as a prefix and run them. For the coverage report, first run coverage run -m pytest and then "coverage report --omit="*/test*" or "coverage html --omit="*/test*" to get the report in html form. The --omit flag indicates that the test folder should not be included.
Packaing information is found in pyproject.toml and setup.cfg. Run the following commands at root folder:
- python -m build (Create packages in dist folder)
- python -m twine upload --repository testpypi dist/*<version_number>* (Repository flag determines which library repo you are uploading your package to and it is good practice to be specific with what you are uploading.)
You can test the package by creating a new venv environment, importing the new package, and then running src/logger_samples/sample.py file to check logging status.
- Pytest is unable to properly capture log outputs to console. (stdout is captured but it is not stored in the capfd object)
- Implement mock logger class to abstract away the underlying python logging library. We are only interested in the testing of the logger class and not its dependencies.
- Re-open last log file to continue
- Log file rolling (prevents log file from becoming too big)
- Allow user chosen lowest logging level (currently internally fixed at DEBUG)