-
Notifications
You must be signed in to change notification settings - Fork 51
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
Unify LORIS-MRI logging #1191
base: main
Are you sure you want to change the base?
Unify LORIS-MRI logging #1191
Conversation
aa54f55
to
ef1632d
Compare
a157f00
to
5aae545
Compare
Tested using If you want to inspect the diff yourself, here is what I got: Main:
This PR:
I used the following scripts to uniformize the timestamps across the diffs: #!/bin/sh
cp main.txt main_copy.txt
cp pr.txt pr_copy.txt
sed -i -e 's/10-5-Wl4f_6/10-00-abcdef/g' main_copy.txt
sed -i -e 's/10-15-d5v5D4/10-00-abcdef/g' pr_copy.txt
sed -i -e 's/10h06m53s_hv0qp2_x/10h00m00s_abcdefgh/g' main_copy.txt
sed -i -e 's/10h08m15s_isxuj3lf/10h00m00s_abcdefgh/g' main_copy.txt
sed -i -e 's/10h16m19s_szr6cbl0/10h00m00s_abcdefgh/g' pr_copy.txt
sed -i -e 's/10h17m12s_yyfmqxed/10h00m00s_abcdefgh/g' pr_copy.txt The changes that remain are mostly:
I also checked that the log file exists in the LORIS log directory and that everything was logged in the database. |
5aae545
to
451bc40
Compare
Tested it with Main:
This PR:
|
9e90906
to
7957846
Compare
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.
@maximemulder testing this branch failed on a fresh DB install because there is no row yet in the notification_types table and it needs to be created if no rows are found.
|
||
notification_session = Session(self.db_engine) | ||
notification_type_name = f'PYTHON {self.script_name.replace("_", " ").upper()}' | ||
notification_type = get_notification_type_with_name(self.db, notification_type_name) |
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.
This returns an error on a fresh DB install because there is no row yet for that kind of notification so if that happens, it needs to be created.
Description of the PR
This PR is a rewrite of the logging and I/O modules of LORIS-MRI.
Problems of the current architecture
There are several problems with the current logging and I/O architecture of LORIS-MRI:
Log
class. TheBasePipeline
andImagingIO
classes build on top ofLog
provide better abstractions, with some amount of duplication between those two classes (some scripts simply useprint
but they are not the subject of this PR).BasePipeline
class is too coupled with the DCM2BIDS pipeline to be generalized.BasePipeline
andImagingIO
classes handle both logging and file system operations, which are two different responsibilities.is_error = 'Y' | 'N'
andis_verbose = 'Y' | 'N'
.Description of the new architecture
This PR adds the following:
lib.env.Env
dataclass that stores generic information about a running script.lib.logging
module that handles log operations.lib.file_system
module that handles file system operations.make_env
function that allows to build anEnv
from aLorigGetOpt
object (note that the environment does not directly depend onLorisGetOpt
, it could also be built manually).Those abstractions aim to replace the
Log
andImagingIO
classes, as well as theBasePipeline
logging methods. They are script-agnostic, remove the existing duplication, are statically typed, use the SQLAlchemy abstractions, and provide more convenient interfaces IMO. They also use simple functions instead of classes, which I think is better for simplicity, reusability and testability.Backwards compatibility
This PR is backwards compatible as the old abstractions are not replaced by this PR. They are however annotated as depcreated to let some time for external scripts to move to the old abstractions. All the uses of the old abstractions in LORIS-MRI are replaced by the new abstractions in this PR, so the deprecated files remain only for external scripts compatibility.
Ultimately (once the migration is finished), I would like the new logging module to take the
lib.log
namespace though (the same way I would like the new database module to use thelib.database
module).Final notes
I am not an expert in logging, but I am not a fan of how logging is done in LORIS-MRI (printing AND writing to a log file that does not differentiate stdout and stderr AND inserting into the database on every print). I much prefer how the LORIS process manager does it, which is redirecting stdout and stderr to some files, and saving these files paths in the database. Nevertheless, the current behaviour is conserved in this PR as it is only an architectural change, and I believe this PR is an improvement no matter how LORIS-MRI logging evolves in the future.