How to : use System.out or logger in Restlet

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to : use System.out or logger in Restlet

saurabh narayan singh
Hi,
i have restlet and i want to check the intermediate values in various methods, for instance refer to the code below

 @Override
    public synchronized Restlet createInboundRoot(){
        Authenticator auth = new myAuthenticator();
        Validator val = new myValidator(getContext());
        Filter fil1 = new myFilter();
        Router r = new Router();
        r.attach("/hellowrld​",HelloWorldResource​.class);
        fil1.setNext(auth);

        /***********See here***************/
        System.out.println("hello world");     Logger.getLogger(TestRestlet.class.getName()).log(Level.SEVERE, null, " Hello");

        auth.setNext(val);
        val.setNext(r);
        return fil1;
    }

Now when i start the service, it prints and logs once, but after that, even if i reinvoke the restlet it won't print.

Same is the case with Filter and validator, i was trying to check whether or not validatePresence is being called by inserting a S.O.P there, but no output.

Q 1. Whats the reason behind this behavior ?
Q 2. How do we overcome this, can we use any other Logger or am i looking at the wrong place ?

Any help will be appreciated,

Regards,
Saurabh Narayan Singh

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3074802
Reply | Threaded
Open this post in threaded view
|

Re: How to : use System.out or logger in Restlet

Tim Peierls
The code in createInboundRoot is called once at application startup, so any logging in it is only called once.

It sounds like you're trying to get logging each time a request is handled. For that you need to instrument the Restlets themselves, either in their handle() methods or in more specific methods. For Filters, you can add logging in the beforeHandle and afterHandle methods.

Incidentally, you can just use getLogger(). There's no need for System.out.print.

--tim


On Wed, Mar 19, 2014 at 1:14 AM, saurabh narayan singh <[hidden email]> wrote:
Hi,
i have restlet and i want to check the intermediate values in various methods, for instance refer to the code below

 @Override
    public synchronized Restlet createInboundRoot(){
        Authenticator auth = new myAuthenticator();
        Validator val = new myValidator(getContext());
        Filter fil1 = new myFilter();
        Router r = new Router();
        r.attach("/hellowrld",HelloWorldResource.class);
        fil1.setNext(auth);

        /***********See here***************/
        System.out.println("hello world");     Logger.getLogger(TestRestlet.class.getName()).log(Level.SEVERE, null, " Hello");

        auth.setNext(val);
        val.setNext(r);
        return fil1;
    }

Now when i start the service, it prints and logs once, but after that, even if i reinvoke the restlet it won't print.

Same is the case with Filter and validator, i was trying to check whether or not validatePresence is being called by inserting a S.O.P there, but no output.

Q 1. Whats the reason behind this behavior ?
Q 2. How do we overcome this, can we use any other Logger or am i looking at the wrong place ?

Any help will be appreciated,

Regards,
Saurabh Narayan Singh

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3074802