Skip to content

mirrorweb/sawmill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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:

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

License

MIT

About

A custom Python logger which can be configured to output logs to the user's preference.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published