Can I disable build output from my shared library?

I like to keep my build logs very neat and tidy by only displaying the most important information. Sometimes I have to use a step that blurts out a ton of information to the build log. I would like to be able to silence steps on demand.

I have tried the following from my shared library but it didn’t work.

@NonCPS
void noOutput() {
    PrintStream stream = new PrintStream(new File('/dev/null')
    System.setOut(stream)
}

also…

@NonCPS
void noOutput() {
    LogManager manager = LogManager.getLogManager()
    manager.reset()
}

When I used these in a job…

println('visible')
myLogger.noOutput()
println('not visible')

But both were still visible =/

If you have a way I can disable build output and then re-enable it, then would love to hear about it.

I’m thinking of something like…

println('visible')

build.silent {
    println('NOT visible')
}

and also having a DEBUG environment variable that would print stuff even in the silent block.

Not sure it works this way. I am pretty sure everything goes to the log and consequences of messing with system output for the entire controller may not be worth trying (remember that pipeline is running in same JVM as the controller) - My guess is that this sort of a thing is blocked by security sandbox - your best bet is to run that section of the build as an external process

What I would love to see is some filtering for the log output - you already can do some of that with some plugins like timestamper (adds/modifies timestamps with format selected at view time) and the pipeline-view plugin (lets you see console for specific steps) - would be nice to be able to turn off some of the output