Search code examples
javaantlrantlr4stringtemplatestringtemplate-4

Can you prevent StringTemplate output to stderr?


Im currently using the following to output to a servlet using StringTemplate:

(ST)page.render();

When I do this, StringTemplate prints warnings to Stderr; filling up log files with useless warnings is not ideal.

If I understand the documentation correctly, will the following fix this:

STWriter out = new MyCustomWriter(response.getWriter());
page.write((STWriter)out, (STErrorListener)myListener);

And on a side note, will doing this save having to build an entire page of strings in memory?


Solution

  • I've put some time into digging through the javadoc and mucking around with the code, the following seems to suppress the errors completely:

    page.write(new NoIndentWriter(response.getWriter()), new ErrorBuffer());
    

    The ErrorBuffer simply collects all the warnings, which I can then ignore, or process if need be.

    (I should post a separate question about if its possible to prevent this warning, but for now this works)