Grepping a process output

I’m just noting this down because I had to do a lot of reading to get this right. Now that I’m actually using log libraries in a good way for my scripts, I want to dial up and down the log level easily – but setting the loglevel on my overall script to debug makes EVERYTHING output, and I don’t really need every library’s output. I’m sure there’s a better way to control the log level of a specific logger for my script from the command line, but this works for me in a quick and dirty way.

env LOGLEVEL=DEBUG ./myscript.py |& grep my_logger_name

I set the log level for just this run, then use the |& to capture both stdout and stderr, then pass that to grep.

But wait, there's more

  • Just kidding, nothing's related to this.

Leave a Reply

Your email address will not be published. Required fields are marked *