Hello everyone! If I am working on a pipeline that...
# nostupidquestions
m
Hello everyone! If I am working on a pipeline that is based on nf-core style, but isn’t an nf-core pipeline, is there a way to copy or provide a configuration option for people to move the .nextflow.log to somewhere inside the outdir? Like inside the pipeline_info directory or anywhere else inside the outdir. Most of our users so far are very unfamiliar with nextflow and the .nextflow.log file being in the launch directory has been a repeated point of confusion
You can specify a custom location and name with the
-log parameter
I'm not sure if there is a configuration option though
👍 1
p
Probably not, because the log will start being written before the config parser loads
👍 2
In fact I'd forgotten that there was a CLI option. I guess this is used by the the wrapper that launches the Nextflow Java process.
😅 1
m
Is this an insane way to work around that? Inside a
workflow.onComplete
, such as inside
workflow PIPELINE_COMPLETION
‘s
workflow.onComplete
add
Copy code
def logFile = file('.nextflow.log')
if (outdir && logFile.exists()) {
    def newLoc = file(outdir).resolve('.nextflow.log')
    log.debug("Moving .nextflow.log to: ${newLoc}")
    Files.copy(logFile, newLoc, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
}
and add
Copy code
import java.nio.file.Files
import java.nio.file.StandardCopyOption
at the top of the file. Which of course won’t always work, like if the pipeline was killed and wasn’t able to do do a graceful exit, but most of the time does it. And you can still tell people about the edge cases (or put a placeholder that says check launch directory if this file doesn’t get populated or something, or even copy periodically but that seems not necessary)
t
I always use wrapper scripts to start my pipelines, and I would recommend that (e.g. so you can track which parameters were used). If you do that, you could simply have a
cp -a .nextflow.log /path/to/outdir/nextflow_$(date -Is).log
at the end of it. That seems more simple and flexible than messing with
workflow.onComplete
.