Re: disable logging

"Attila Szegedi" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Below is a full testcase I produced -- basically same as your code, except
that "buffer.toString()" was replaced with literal template "${foo}", and
there's just an empty map in the model.
It prints nothing at all on console, nor with Freemarker 2.3.12, nor with
2.4 preview. All works as expected.

If I remove the selectLoggerLibrary() invocation, it'll bind to Log4J (as I
have Log4J in the classpath...) and spit few lines to the console. If I
remove the exception handler, it'll print the exception to the console. But
if the log library is set to NONE, and exception handler to IGNORE, it is
completely silent.

So, works for me :-)

Attila.

import java.io.StringWriter;

import java.io.Writer;

import java.util.HashMap;

import java.util.Map;


import freemarker.template.Configuration;

import freemarker.template.DefaultObjectWrapper;

import freemarker.template.Template;

import freemarker.template.TemplateExceptionHandler;



public class TestNoLog

{

    public static void main(String[] args) throws Exception

    {

        freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.
LIBRARY_NONE);

        Configuration cfg= new Configuration();

        cfg.setObjectWrapper(new DefaultObjectWrapper());

        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.
IGNORE_HANDLER);

        Template template=new Template("modelo", new java.io.StringReader(
"${foo}"), cfg);

        Writer out=new StringWriter();

        Map root=new HashMap();

        template.process(root, out);

        out.flush();

    }

}



On Thu, Aug 14, 2008 at 11:43 PM, Gabriel Luhers Graça <
[email protected]> wrote:

> Hi all,
>
>  I'm using freemarker along with struts2 and can't turn off the enormous
> stack traces that are printed on stdout.
>
>  My code goes like this:
>
>
>  freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
>                Configuration cfg= new Configuration();
>                cfg.setObjectWrapper(new DefaultObjectWrapper());
>
>  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
>                Template template=new Template("modelo", new
> java.io.StringReader(buffer.toString()), cfg);
>                Writer out=new StringWriter();
>                Map root=criarVariaveis();
>                template.process(root, out);
>                out.flush();
>
>  I thought the first line would do the trick, but it doesn't have any
> effect.
>
>  I would also like to leave the offending expressions on the processed
> document, but I've found no simple to way to extract it from the exceptions
> (except for extricating from the message string with a regex). Is there a
> simpler way?
>
>  Thanks,
>
> Gabriel.
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.