Skip to content

Commit 8159ed3

Browse files
kannon92mr-c
authored andcommitted
feat: Enable logging to host system as container runs
1 parent 2232bcc commit 8159ed3

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

cwltool/argparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def arg_parser() -> argparse.ArgumentParser:
4040
help="Output directory. The default is the current directory.",
4141
)
4242

43+
parser.add_argument(
44+
"--log-host",
45+
type=str,
46+
default="",
47+
help="Output directory. The default is the current directory.",
48+
)
49+
50+
4351
parser.add_argument(
4452
"--parallel",
4553
action="store_true",

cwltool/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None:
118118
self.pull_image = True # type: bool
119119
self.rm_container = True # type: bool
120120
self.move_outputs = "move" # type: str
121+
self.log_host = ""
121122
self.streaming_allowed: bool = False
122123

123124
self.singularity = False # type: bool

cwltool/job.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ def _execute(
267267
menv.pass_through_env_vars(env)
268268
menv.set_env_vars(env)
269269

270+
outdir_stdout_stderr = self.outdir if runtimeContext.log_host == "" else runtimeContext.log_host
271+
272+
270273
_logger.info(
271274
"[job %s] %s$ %s%s%s%s",
272275
self.name,
@@ -278,8 +281,8 @@ def _execute(
278281
]
279282
),
280283
" < %s" % self.stdin if self.stdin else "",
281-
" > %s" % os.path.join(self.outdir, self.stdout) if self.stdout else "",
282-
" 2> %s" % os.path.join(self.outdir, self.stderr) if self.stderr else "",
284+
" > %s" % os.path.join(outdir_stdout_stderr, self.stdout) if self.stdout else "",
285+
" 2> %s" % os.path.join(outdir_stdout_stderr, self.stderr) if self.stderr else "",
283286
)
284287
if self.joborder is not None and runtimeContext.research_obj is not None:
285288
job_order = self.joborder
@@ -308,21 +311,22 @@ def _execute(
308311
stdin_path = rmap[1]
309312

310313
stderr_path = None
314+
outdir_stdout_stderr = self.outdir if runtimeContext.log_host == "" else runtimeContext.log_host
311315
if self.stderr is not None:
312-
abserr = os.path.join(self.outdir, self.stderr)
316+
abserr = os.path.join(outdir_stdout_stderr, self.stderr)
313317
dnerr = os.path.dirname(abserr)
314318
if dnerr and not os.path.exists(dnerr):
315319
os.makedirs(dnerr)
316320
stderr_path = abserr
317321

318322
stdout_path = None
319323
if self.stdout is not None:
320-
absout = os.path.join(self.outdir, self.stdout)
324+
absout = os.path.join(outdir_stdout_stderr, self.stdout)
321325
dnout = os.path.dirname(absout)
322326
if dnout and not os.path.exists(dnout):
323327
os.makedirs(dnout)
324328
stdout_path = absout
325-
329+
_logger.debug("stderr: %s stdout: %s hostdir: %s", stderr_path, stdout_path, outdir_stdout_stderr)
326330
commands = [str(x) for x in runtime + self.command_line]
327331
if runtimeContext.secret_store is not None:
328332
commands = cast(

cwltool/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,9 @@ def main(
12621262
runtimeContext.move_outputs = "copy"
12631263
runtimeContext.tmp_outdir_prefix = args.cachedir
12641264

1265+
if args.log_host:
1266+
runtimeContext.log_host = args.log_host
1267+
12651268
runtimeContext.secret_store = getdefault(
12661269
runtimeContext.secret_store, SecretStore()
12671270
)

0 commit comments

Comments
 (0)