idia-astro/frocc

Write CASA logs to named log directory

Opened this issue · 2 comments

CASA logs get written to casa-timestamp.log, but it would be useful if they were named like the SLURM logs, according to the task and job / task array ID that wrote them.

It is possible to rename the logs immediately after importing casatasks, such as:

import os
import casatasks
casatasks.casalog.setlogfile('logs/{SLURM_JOB_NAME}-{SLURM_ARRAY_JOB_ID}_{SLURM_ARRAY_TASK_ID}.casa'.format(**os.environ))

However, it seems a very short default CASA log with the timestamp still gets written before this.

As I've looked more into this, it seems there is still a bunch of stuff that goes to the default log, at least when you're running MPI (not sure about otherwise), so I've also found it's necessary to add this at the end:

os.rename(casatasks.casalog.logfile(),'logs/{SLURM_JOB_NAME}-{SLURM_ARRAY_JOB_ID}_{SLURM_ARRAY_TASK_ID}.mpi'.format(**os.environ))

It seems necessary to first store the output name, before renaming it with setlogfile(), using:

logfile=casatasks.casalog.logfile()