Lesson 7: Logging Data

When your code runs in space, you won't be there to watch the screen. You need to record everything that happens to a file so you can analyze it later.

Session Goals
  • Use the logzero library.
  • Understand Log Levels (Info, Warning, Error).
  • Write sensor data to a Log File.

The Mission Task

We need to create a reliable data logger that records the temperature and humidity at regular intervals. This data is crucial for the experiment analysis.

Key Concepts

Logging
The process of recording events, messages, and data to a file for permanent storage.
Log Levels
Categories of logs: INFO (normal events), WARNING (potential issues), ERROR (failures).
CSV Format
Comma-Separated Values. A common text format for data where each value is separated by a comma.

Logzero

Robust and easy-to-use logging for Python.

from logzero import logger, logfile
UsageDescription
logfile("file.log")Set the file to write logs to.
logger.info(msg)Log an informational message.
logger.warning(msg)Log a warning message.
logger.error(msg)Log an error message.

Sense HAT

Controls the LED matrix and reads environmental sensors.

from sense_hat import SenseHat
UsageDescription
sense.get_temperature()Get temperature in Celsius.
sense.get_humidity()Get relative humidity (%).

Mission Control Interface

Output Terminal
Ready to execute...