Skip to content

Commit f52773c

Browse files
AnHeuermannclaude
andauthored
Redirect parser stdout/stderr to parsing log file (#22)
Capture stdout and stderr during BaseModelica.create_odeproblem() using a Pipe, so that ANTLR syntax error messages are written to the per-model parsing log instead of cluttering the terminal. The captured output is appended after the summary lines (Time/Success). Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a359056 commit f52773c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/parse_bm.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,34 @@ function run_parse(bm_path::String, model_dir::String,
1818
parse_error = ""
1919
ode_prob = nothing
2020

21-
log_file = open(joinpath(model_dir, "$(model)_parsing.log"), "w")
21+
log_file = open(joinpath(model_dir, "$(model)_parsing.log"), "w")
22+
stdout_pipe = Pipe()
2223
println(log_file, "Model: $model")
2324
logger = Logging.SimpleLogger(log_file, Logging.Debug)
2425
t0 = time()
2526
try
2627
# create_odeproblem returns an ODEProblem using the Experiment
2728
# annotation for StartTime/StopTime/Tolerance/Interval.
28-
# Redirect all library log output (including Symbolics warnings)
29-
# to the log file so they don't clutter stdout.
30-
ode_prob = Logging.with_logger(logger) do
31-
BaseModelica.create_odeproblem(bm_path)
29+
# Redirect Julia log output to the log file and stdout/stderr to a
30+
# buffer so they can be appended after the summary lines.
31+
ode_prob = redirect_stdout(stdout_pipe) do
32+
redirect_stderr(stdout_pipe) do
33+
Logging.with_logger(logger) do
34+
BaseModelica.create_odeproblem(bm_path)
35+
end
36+
end
3237
end
3338
parse_time = time() - t0
3439
parse_success = true
3540
catch e
3641
parse_time = time() - t0
3742
parse_error = sprint(showerror, e, catch_backtrace())
3843
end
44+
close(stdout_pipe.in)
45+
captured = read(stdout_pipe.out, String)
3946
println(log_file, "Time: $(round(parse_time; digits=3)) s")
4047
println(log_file, "Success: $parse_success")
48+
isempty(captured) || print(log_file, "\n--- Parser output ---\n", captured)
4149
isempty(parse_error) || println(log_file, "\n--- Error ---\n$parse_error")
4250
close(log_file)
4351

0 commit comments

Comments
 (0)