Diet-Microbiome-Interactions-Lab / GeneralTools

General Properties of FASTAs
MIT License
3 stars 1 forks source link

Logging support #7

Closed mavcook closed 4 months ago

mavcook commented 4 months ago

This should meet a basic logging and configuration needs for the first users and use cases. There are improvements that can be made (mentioned below), but for now, I think this gets us to 80% or more of what we need:

Note: I'm holding off on a bit of details in the README that will change in an upcoming PR working on configuration features

Changes

Before

$ fileflux filter seqlength type: fasta file: example.fasta
Found type: fasta, we can work with this...
Matched Fasta or fasta to fasta
...

After

$ fileflux filter seqlength type: fasta file: example.fasta
[23:32:12 INFO] - Found type: fasta, we can work with this...
[23:32:12 INFO] - Matched Fasta or fasta to fasta
...

and generates

~/.caragols/logs/log.txt      # DEBUG level, with more info, plain text
[2024-05-09T23:32:12-0700 INFO caragols main.py:cli:45] - Found type: fasta, we can work with this...
[2024-05-09T23:32:12-0700 INFO caragols main.py:cli:49] - Matched Fasta or fasta to fasta

~/.caragols/logs/log.jsonl    # DEBUG level, json
{"asctime": "2024-05-09T23:32:12-0700", "msecs": 558.0, "levelname": "INFO", "name": "caragols", "filename": "main.py", "module": "main", "process": 11789, "processName": "MainProcess", "thread": 8358968000, "funcName": "cli", "lineno": 45, "message": "Found type: fasta, we can work with this..."}
{"asctime": "2024-05-09T23:32:12-0700", "msecs": 558.0, "levelname": "INFO", "name": "caragols", "filename": "main.py", "module": "main", "process": 11789, "processName": "MainProcess", "thread": 8358968000, "funcName": "cli", "lineno": 49, "message": "Matched Fasta or fasta to fasta"}

References

For learning more about python logging, the docs are decent, but this video by mCoding is good

Future improvements