Disable Blue Console Warnings

Hello,

How can I disable the blue console warning that show up when I am missing a file?

For example I do a check to see if an image/file exists before loading like so:

      if ((img = loadImage("file.jpg")) != null) { //check if image exists
        image(img, x, y);
        }

BUT I still get “The file “file.jpg” is missing of inaccessible” in the console. Since I am checking for the existence of many files and I already know they may not exist can I stop the warnings?

Thanks!
mark

Hi @megrimm

you can suppress it that way …

Cheers
— mnse

PS: perhaps I should mention that this is for demonstration purposes only, how to suppress output to System.err. Better check if file exists and do further processing depending on the result… See: below post from @GoToLoop

import java.io.PrintStream;
import java.io.OutputStream;

final PrintStream defaultStderr = System.err;

void setup() {
  size(100, 100);

  System.err.println("Disable error message now ...!");
  disableErrorConsole();
  
  // your image loading here
  System.err.println("I'm not printed to error console :/");

  enableErrorConsole();
  System.err.println("Yay! Here we go again!");
}

void disableErrorConsole() {
  System.setErr(new PrintStream(new OutputStream() {
    @Override
    public void write(int b) {}
  }));
}

void enableErrorConsole() { 
  System.setErr(defaultStderr);
}
// https://discourse.Processing.org/t/disable-blue-console-warnings/38056/3
// GoToLoop (2022/Jul/22)

static final String IMAGE_FILENAME = "file.jpg";
PImage img;

void settings() {
  if (fileExists(IMAGE_FILENAME)) {
    img = loadImage(IMAGE_FILENAME);
    size(img.width, img.height);
  }
}

void setup() {
  if (img == null)  exit();
  noLoop();
}

void draw() {
  background(img);
}

boolean fileExists(final String filename) {
  return dataFile(filename).isFile() || sketchFile(filename).isFile();
}
2 Likes