Skip to content

Conversation

@nateinaction
Copy link
Member

@nateinaction nateinaction commented Sep 1, 2025

Summary

This PR provides feedback on #299

How was this tested

  • Added new unit tests
  • Ran code on hardware (screenshots are helpful)
  • Other (Please describe)

boot_out.txt first run:

Adafruit CircuitPython 9.2.8 on 2025-05-28; PROVES Kit v4 with rp2040
Board ID:proveskit_rp2040_v4
UID:E4639C3563112E2D
boot.py output:
Disabled USB drive
Remounted root filesystem
Mount point /poke created.
Enabled USB drive

boot_out.txt subsequent runs:

Adafruit CircuitPython 9.2.8 on 2025-05-28; PROVES Kit v4 with rp2040
Board ID:proveskit_rp2040_v4
UID:E4639C3563112E2D
boot.py output:
Disabled USB drive
Remounted root filesystem
Mount point /poke already exists.
Enabled USB drive

Demonstrating logging to file:
Captura de pantalla 2025-09-01 a la(s) 19 03 31

import traceback
from collections import OrderedDict

import adafruit_pathlib
Copy link
Member Author

@nateinaction nateinaction Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I previously suggested using adafruit_pathlib and you've done a good job implementing it! I spent some time with the implementation using pathlib and decided that it would cause more pain than it's worth:

  • All CircuitPython functions that interact with the filesystem expect a string path which would mean that we would always need to output the path to a string anyways.
  • adafruit_pathlib did not have any join() semantics which made adding to a Path object clunky. (this could be submitted upstream)
  • Most modules in pysquared use the Logger which means we would have needed to mock away the use of adafruit_pathlib in many many test files.

So ultimately, I removed it.

Copy link
Member Author

@nateinaction nateinaction Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time on this file to reduce its complexity and to make sure the name made sense 🤞... naming is hard.

self.colorized: bool = colorized

try:
self.sd_path = self.sd_path / "logs"
Copy link
Member Author

@nateinaction nateinaction Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to have the logger be opinionated about the directory location so now we just accept whatever path is provided to the logger.

Comment on lines 101 to 111
if log_dir is not None:
try:
# Octal number 0o040000 is the stat mode indicating the file being stat'd is a directory
directory_mode: int = 0o040000
st_mode = os.stat(log_dir)[0]
if st_mode != directory_mode:
raise ValueError(
f"Logging path must be a directory, received {st_mode}."
)
except OSError as e:
raise ValueError("Invalid logging path.") from e
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone sets a log location that doesn't exist or is not a directory, we'll error out.

Comment on lines 21 to +24
try:
from mocks.circuitpython.microcontroller import Processor
except ImportError:
from microcontroller import Processor
except ImportError:
from mocks.circuitpython.microcontroller import Processor
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR: switching this order is possible now because of #304. With this order change, the IDE shows more accurate hints.

Comment on lines -165 to -176
try:
json_output = json.dumps(json_order)
except TypeError as e:
json_output = json.dumps(
OrderedDict(
[
("time", asctime),
("level", "ERROR"),
("msg", f"Failed to serialize log message: {e}"),
]
),
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This became no longer necessary after #228 but was left in. It has no tests and is no longer required so I removed it.

Comment on lines 48 to 69
"pysquared.boot",
"pysquared.config",
"pysquared.hardware",
"pysquared.hardware.imu",
"pysquared.hardware.burnwire.manager",
"pysquared.hardware.burnwire",
"pysquared.hardware.imu.manager",
"pysquared.hardware.magnetometer",
"pysquared.hardware.imu",
"pysquared.hardware.light_sensor.manager",
"pysquared.hardware.magnetometer.manager",
"pysquared.hardware.radio",
"pysquared.hardware.magnetometer",
"pysquared.hardware.power_monitor.manager",
"pysquared.hardware.power_monitor",
"pysquared.hardware.radio.manager",
"pysquared.hardware.radio.packetizer",
"pysquared.hardware.power_monitor",
"pysquared.hardware.power_monitor.manager",
"pysquared.hardware.temperature_sensor",
"pysquared.hardware.radio",
"pysquared.hardware.sd_card",
"pysquared.hardware.temperature_sensor.manager",
"pysquared.hardware.burnwire",
"pysquared.hardware.burnwire.manager",
"pysquared.hardware.light_sensor.manager",
"pysquared.hardware.temperature_sensor",
"pysquared.hardware",
"pysquared.nvm",
"pysquared.protos",
"pysquared.rtc",
"pysquared.rtc.manager",
"pysquared.rtc",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 1, 2025

@nateinaction nateinaction marked this pull request as ready for review September 2, 2025 00:08
@nateinaction nateinaction requested review from a team, asiemsen and evan-ortiz September 2, 2025 00:09
Copy link
Contributor

@asiemsen asiemsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I would love to go over and review the design behind the tests sometime so that I can start implementing some of these in the future! I also saw your most recent commit that uses a setter for the log directory, which I think was implemented really well. Thanks again for all your help on this.

@nateinaction nateinaction merged commit c9049b0 into sdcard_logging Sep 2, 2025
5 checks passed
@nateinaction nateinaction deleted the sdcard_logging-ngay-2 branch September 2, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants