Have you ever been working on code and needed a view into what was going on as it runs (or tries to)? In many environments you can go into a debugger and poke around. We don't have that ability in CircuitPython, though. If you're like this author, you sprinkle tactical print statements as needed.

Afterwards you probably go through and remove them or comment them out. Sometimes you miss some. Sometimes you'd like to leave them in place and be able to turn them on and off. There are times when you'd like to see some debugging information, and other times when you want to be notified of critical errors only.

A logging framework will let you do all that and more.

Specifically, the logging framework described in this guide will:

  • let you output messages at one of several levels of priority,
  • ignore messages below a specific priority,
  • automatically add a timestamp to messages,
  • provide the string format method support for building messages,
  • give you convenience methods for the outputting at standard priority levels,
  • control where messages go, and
  • make it easy to add new places for messages to go.

This guide will go over the use of the framework, walk through the implementation, and work through an example of adding a new destination capability.

Parts

As this service uses RAM and space for longer programs, this guide will note use on M4 and nRF52840-based boards.

Front view of a Adafruit PyPortal - CircuitPython Powered Internet Display with a pyportal logo image on the display.
PyPortal, our easy-to-use IoT device that allows you to create all the things for the “Internet of Things” in minutes. Make custom touch screen interface...
$54.95
In Stock
Angled shot of a Adafruit Metro M4 feat. Microchip ATSAMD51.
Are you ready? Really ready? Cause here comes the fastest, most powerful Metro ever. The Adafruit Metro M4 featuring the Microchip ATSAMD51. This...
$27.50
In Stock
Angled shot of a Adafruit Feather M4 Express.
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox,...
$22.95
In Stock
Angled shot of a Adafruit Feather nRF52840 Express.
The Adafruit Feather nRF52840 Express is the new Feather family member with Bluetooth Low Energy and native USB support featuring the nRF52840!  It's...
$24.95
In Stock
USB cable - USB A to Micro-B - 3 foot long
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or...
$2.95
In Stock

This guide was first published on Mar 18, 2019. It was last updated on Dec 08, 2023.

This page (Overview) was last updated on Mar 06, 2019.

Text editor powered by tinymce.