Skip to content
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

feat: divert log to standard output for debugging #958

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion metatlas/untargeted/run_untargeted_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
step_bools = check_skipped_steps(args)

##### Configure logging
mzm.call_logger(log_filename=args.log_file, log_level=args.log_level, log_format=args.log_format)
mzm.call_logger(log_filename=args.log_file, log_level=args.log_level, log_format=args.log_format, log_to_stdout=args.log_to_stdout)

##### Kick off the script
start_message = mzm.start_script(script="run_untargeted_pipeline.py")
Expand Down Expand Up @@ -102,6 +102,7 @@ def add_arguments(parser):
parser.add_argument('--log_file', type=str, default='/global/cfs/cdirs/m2650/untargeted_logs/untargeted_pipeline.log', help='Log file name with full path')
parser.add_argument('--log_level', type=str, default='INFO', help='Logger level. One of [DEBUG, INFO, WARNING, ERROR, or CRITICAL]')
parser.add_argument('--log_format', type=str, default='%(asctime)s - %(levelname)s - %(message)s', help='Logger format')
parser.add_argument('--log_to_stdout', action='store_true', help='Log to stdout instead of a file')

def check_args(args):
##### Check if the input arguments are valid
Expand Down
8 changes: 7 additions & 1 deletion metatlas/untargeted/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
def call_logger(log_filename: str, log_level: str, log_format: str):
logging.basicConfig(filename=log_filename, level=log_level, format=log_format, filemode='a')

def call_logger(log_filename: str, log_level: str, log_format: str, log_to_stdout: bool):
if log_to_stdout:
logging.basicConfig(stream=sys.stdout, level=log_level, format=log_format)
else:
logging.basicConfig(filename=log_filename, level=log_level, format=log_format, filemode='a')

def start_script(script:str=None) -> str:
"""
Kick off script with a timestamp for log
Expand Down Expand Up @@ -1016,6 +1022,7 @@ def mirror_raw_data_to_gnps2(
if not os.path.exists(local_directory):
logging.error(f"Local directory for {project} raw data not found after trying several possible alternatives. Exiting.")
return
local_directory = Path(local_directory)
remote_subdir = local_directory.parent.name # Use the same subdir as on perlmutter instead of inferring from the project name directly
remote_directory = f"/raw_data/{remote_subdir}/{project}"
polarity_directory = f"{remote_directory}/{polarity}"
Expand All @@ -1042,7 +1049,6 @@ def mirror_raw_data_to_gnps2(
logging.error(f"Failed to create remote directory {polarity_directory} at GNPS2: {e}")

try:
local_directory = Path(local_directory)
logging.info("Walking through local directory %s and uploading mzML files to GNPS2..."%(local_directory))
for file_path in local_directory.rglob('*'):
if file_path.is_file() and file_path.suffix == '.mzML' and polarity_short in file_path.name:
Expand Down
Loading