https://github.com/mirrorweb/sawmill
A custom Python logger which can be configured to output logs to the user's preference.
https://github.com/mirrorweb/sawmill
devops-team
Last synced: 3 months ago
JSON representation
A custom Python logger which can be configured to output logs to the user's preference.
- Host: GitHub
- URL: https://github.com/mirrorweb/sawmill
- Owner: mirrorweb
- License: mit
- Created: 2019-06-03T11:13:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-12T14:07:48.000Z (almost 2 years ago)
- Last Synced: 2024-07-13T15:15:28.971Z (almost 2 years ago)
- Topics: devops-team
- Language: Python
- Homepage:
- Size: 134 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sawmill
A custom Python logger which can be configured to output logs to the user's preference.
### .env
Sawmill only has 1 environmental variable:
| Name | Required By | Purpose |
|---------------------|---------------------|---------------------|
| SAWMILL_DEVELOPER_LOGS | `sawmill.logger` | True/False - switches between outputting logs to terminal/local file store and outputting to sys.stdout |
### usage
Instead of doing the usual logger setup:
```python
import logging
import sys
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter('%(levelname)s - %(message)s'))
console_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s %(filename)s'))
stdout_handler.setLevel(logging.INFO)
logger.addHandler(stdout_handler)
logger.info('Logger has been created')
```
Do this instead:
```python
from sawmill.logger import Sawmill
logger = Sawmill.new_logger(__name__)
logger.info('Sawmill logger has been created')
```
All the logging handlers & formatters are handled in the background removing the need to have the setup code
at the top of your *.py files.
# How To
Change log format
----
Log format can be different per output type AND log level.
Go into the sawmill/config.py file and select a 'MsgFormat' Enum option.
Define a new log format
----
Go into sawmill/utils.py and add to the existing 'MsgFormat' Enum.
Change log colours
----
Go into the sawmill/config.py file and select an Enum option for primary, secondary & tertiary colours.
Define a new colour
----
Colour Enum values are [256 colour codes].
Go into sawmill/utils.py and add to the existing 'Colour' Enum.
Change the log file location
----
Go into sawmill/config.py and update the dir / filename. The next time the app runs the new filename/folder will be used.
### Terminal commands
- `make env`
builds the project depedencies to a virtural environment using Poetry
- `make run`
Doesn't do anything! Just here for consistency with our other projects
- `$ make test`
Runs the test suite
- `make lint`
formats code
- `make docs`
uses Sphinx to auto-create documentation from doc-strings
- `make requirements`
generates a up-to-date requirements.txt file
[256 colour codes]: https://jonasjacek.github.io/colors/
License
----
MIT