A very common convention I’ve seen over the last few years in utilizing python logging is to use the root logger:
logger = logging.getLogger()
This is wrong. Don’t do this. Instead of using the root logger — you should be using a specific logger, and leveraging logging “ancestry”.
In python’s logging module, ancestry is how loggers in functions, modules, and packages inherit configurations from a logger that’s higher up in the package hierarchy. Let’s look at the following package:
│ └── my_package
│ ├── sub_folder
│ │ ├── __init__.py …
Ever wanted to set up an ELK stack and get python logging to get there with minimal fuss? Well this is the article for you. We’ll be using a dockerized ELK stack, so if you want to follow along, make sure you install docker and docker-compose. We’ll be using a jupyter notebook to do our logging testing. I assume you’re familiar with installing python virtual environments and using them, but if you’re not please feel free to brush up on the documentation!
Logging in python is something that won’t matter to you until it matters. If you’ve ever seen a message like one of these, I’m here to explain why it’s a bad idea to ignore them:
W1201: Specify string format arguments as logging function parameters (logging-not-lazy)W1202: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)
When you’re building a production application, logging is never supposed to be disruptive to the application’s function. If you’re not writing code that others have to support, you may not have encountered this problem before — but when other people need to support and troubleshoot your code (Or even if YOU have to support and troubleshoot your code), logging will make that a million times better. …
In both Windows and Linux environments, there’s nothing virtual about a python virtual environment. Since python is compiled, and then you run scripts that use the compiled python interpreter, it’s not conducive to compile it every time you need a new virtual environment. When creating a new virtual environment, you’re not getting a fresh python interpreter; you’re using the environment variables to point your compiled interpreter at a specific interpreter, libraries, and scripts.
With python, there are three primary environment variables for selecting the interpreter, libraries, and scripts that will be available: PYTHONHOME, PYTHONPATH, and PATH. …
Recently I’ve been learning a lot more frontend development, and I keep finding myself using the same pattern over and over for a lot of these personal projects — from a crypto coin logger and grapher to a standard chat site, I’m finding this pairing fairly useful:
I hate doing the same thing over and over — so I finally took the dive and learned cookiecutter the way I should have months ago. Since I took the time to do it, I figured I’d make it available for others — so now we have a cookiecutter template with Angular, FastAPI, and some basic CI/CD using Github Actions. …