-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FileHandler class #22
Conversation
I needed to implement this class for keeping logs on an SD card I was already needed for file storage, I thought it might be a good addition to the library as a LoggingHandler
Updated to address issues in pre-commit |
Also wanted to mention that I tested this with a Feather M4 Express and the Adalogger FeatherWing and got it to work! |
This makes the logging a little less safe, but the arguments and functionality now match expected behavior
Updated to be a better subset of CPython's FileHandler. file now stays open until closed, and arguments match (changed 'overwrite' to 'mode') |
Can you also add a minimal example in the |
Modified from how I use it in my own code
Added a short example, had issues when actually importing the SD card stuff so I just tried to make it clear in the filepath. Let me know if it needs improvement. |
The example should be able to run. I.e. the SD should be set up to be used in the example. I do like keeping the file open between messages for performance. Personally, I think additional handlers should be in separate files to avoid bloat in the main logging file. The serial & null handlers are core enough to be there, but additional handlers shouldn't come along as extra/unused baggage. Finally, I feel that adding the line terminator belongs in the format method (which builds the message) and not emit (which sends the fully formed message to its destination). Here's what I did in a project:
|
Should I make a folder named adafruit_logging, and add the main code as it's init.py, with FileHandler in it's own file? |
That I'm not sure. Typical use is My understanding of python packaging is quite basic, but if the adafruit_logging.py is kept as is, and a directory named adafruit_logging_extansions added for this sort of thing, would that be acceptance/good? It would allow:
Right? Thoughts? |
I think that could work as well. I think it really depends on what structure makes most sense to import. If it makes sense to have to totally removed than I think your proposal makes the most sense, but if it should still be under the adafruit_logging "umbrella", but separately imported then I think my solution might be better suited:
In this case I would just put FileHandler in extensions.py, and the main code in |
Open to whatever makes sense! To me, it seems reasonable to think that everything would be contained in something called adafruit_logging, with additional options pertaining to it to be available directly from itself. |
I like the look of that, but in general I'm not sure about extensions.py being a generic catch-all for extensions. That said, for now it should be fine ... there's only one thing in it. If it eventually starts accreting unrelated stuff it can be revisited. |
Updated per everything said here, let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
@tekktrik do you know how to resolve the merge conflict / need any help with that? |
I'd love some help with that actually! |
I tried to merge it on the command line and I got an error about permissions. Not quite sure how to resolve this. |
@gamblor21 You should be able to! I thought anyway. There's usually a checkbox that says "Allow edits from maintainers" or some such, but I don't see that here (possibly because I have higher perms than that box applies to so I don't see it on someone else's PR). The CircuitPythonLibrarians have write access to the repo, so it must be an issue on the PR itself. I should be able to help though! Do you have the changes somewhere I can get to so I can try to commit to this PR? |
@gamblor21 I tried following the command line instructions that GitHub provides, and it appears to want to push to Edit - I think I see what I was about to do wrong. The command line instructions start with you working with tekktrik's fork, I think, which I did not do. That would explain both the permissions issues and the reason it wants to push to |
@gamblor21 Yeah, the command line instructions provides are intended for @tekktrik to run, and expects permission to push to tekktrik's repository. I am getting the same results as you. We either need to figure out pushing to the PR, getting permissions from tekktrik to access their fork, or walking tekktrik through the process so they can complete it themselves. Dealer's choice! |
@tekktrik do you see beside the greyed out "Merge pull request" there is a link about command line instructions? Can you click on that (it will expand) try to follow those? |
@tekktrik You're not looking in the wrong place - apparently GitHub doesn't provide you with the command line instructions. I am attaching a screenshot here. Hopefully this helps. |
Just followed the instructions, did that help? |
Do I need to create a new PR, or should I merge my new branch into this one that already has a PR? |
Okay, I merged my local main branch into the one here with the PR after the instructions, which is commit 9fd0bc8, does that fix it? |
No it is still showing the error. This is beyond my (limited) github experience, maybe someone else knows more who can help with it more. |
I'm also happy to give access to my repo if that makes life easier :) |
You can give me access to it if you want and I can try it that way again. |
I should have given you access, but I haven't ever done that before, let me know if I didn't. |
Got it! Thank you so much @gamblor21 and @kattni!! |
Thanks for sticking with it! |
Updating https://github.com/adafruit/Adafruit_CircuitPython_74HC595 to 1.3.1 from 1.3.0: > Merge pull request adafruit/Adafruit_CircuitPython_74HC595#19 from tekktrik/feature/add-typing > fix branch name on conduct link > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_AM2320 to 1.2.8 from 1.2.7: > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#22 from tylercrumpton/add-type-hints > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_DHT to 3.6.3 from 3.6.2: > Merge pull request adafruit/Adafruit_CircuitPython_DHT#76 from tylercrumpton/add-type-hints > add docs link to readme Updating https://github.com/adafruit/Adafruit_CircuitPython_HT16K33 to 4.1.6 from 4.1.5: > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#92 from tekktrik/feature/add-typing > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 2.1.5 from 2.1.4: > Merge pull request adafruit/Adafruit_CircuitPython_PM25#20 from process1183/type_annotations > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1305 to 1.3.7 from 1.3.6: > Merge pull request adafruit/Adafruit_CircuitPython_SSD1305#14 from tylercrumpton/add-type-hints > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_ST7735R to 1.5.1 from 1.5.0: > Merge pull request adafruit/Adafruit_CircuitPython_ST7735R#27 from FoamyGuy/type_info > add docs link to readme > Globally disabled consider-using-f-string pylint check Updating https://github.com/adafruit/Adafruit_CircuitPython_WS2801 to 0.10.7 from 0.10.6: > Merge pull request adafruit/Adafruit_CircuitPython_WS2801#23 from rhooper/main > fix branch name in conduct link > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification to 0.9.5 from 0.9.4: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Notification#9 from tekktrik/fix/add-blinka-requirement > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.5.7 from 2.5.6: > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#84 from rhooper/sparkle-mask > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#78 from plugowski/master > add docs link to readme Updating https://github.com/adafruit/Adafruit_CircuitPython_Logging to 3.7.0 from 1.2.9: > Merge pull request adafruit/Adafruit_CircuitPython_Logging#22 from tekktrik/feature/add-file-handler Updating https://github.com/adafruit/Adafruit_CircuitPython_Waveform to 1.3.7 from 1.3.6: > Merge pull request adafruit/Adafruit_CircuitPython_Waveform#22 from rhooper/main > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_WSGI to 1.1.5 from 1.1.4: > Merge pull request adafruit/Adafruit_CircuitPython_WSGI#10 from rhooper/main > fix branch name in conduct link > add docs link to readme > Globally disabled consider-using-f-string pylint check > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template > "Increase duplicate code check threshold "
I needed to implement this class for keeping logs on an SD card I was already needed for file storage, I thought it might be a good addition to the library as a LoggingHandler