# Consistent way to suppress solver output

**URL:** <https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437>\
**Category:** Optimization (Mathematical)\
**Created:** [February 4, 2019, 4:55pm UTC](https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437 "2019-02-04T16:55:20Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Post date:** [January 31, 2020, 10:32am UTC](https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437/6 "2020-01-31T10:32:25Z")

</div>

Just came across this old problem. If you want to use parts of the output you can redirect stdout to a string:

```julia
function capture_stdout(f)
    stdout_orig = stdout
    (rd, wr) = redirect_stdout()
    f()
    close(wr)
    redirect_stdout(stdout_orig)
    read(rd, String)
end

s = capture_stdout() do
    optimize!(model)
end

#print the summary (which starts with "Number of Iterations")
try
    s[findlast("Number of Iterations", s)[1]:end] |> print
catch
    print(s)
end

```

EDIT:  
Digged a bit further and found that most solvers support some kind of [loglevel setting](https://www.isys.uni-stuttgart.de/lehre/lehrveranstaltungen/nmopt/Aufgaben/JuMP_Kurzbeschreibung.pdf), e.g.:

- Ipopt: “print\_level”
- Cbc: “LogLevel”
- Clp: “logLevel”

These options can be set either when initialising the model, e.g.

```julia
model = Model(with_optimizer(Ipopt.Optimizer, tol = 1e-8, max_iter = 1000, print_level = 1))`

```

or afterwards using the MOI Api (which is currently not so nicely documented …)

```julia
MOI.set(model, MOI.RawParameter("print_level"), 1)

```

---

_[View the full topic](https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437)._
