Logging and Error Handling

The {@link oajr.RestContext#REST_logger} property allows you to configure logging for your resource. The interface is shown below:

The {@link oajr.RestLogger#logObjects(Level,String,Object[]) logObjects()} method is particularly useful because it allows you to pass in POJOs as arguments that serialized using {@link oaj.json.SimpleJsonSerializer#DEFAULT_READABLE}, but only if the message is actually logged.

Example:

logger.logObjects(DEBUG, "Pojo contents:\n{0}", myPojo);

By default, the Juneau framework uses the built-in Java Logging API for logging. But you can define your own implementation to use any framework you wish.

The {@link oajr.RestLogger} instance is accessible via the following:

In addition, the logger can be accessed by passing it as a parameter to your REST java method:

@RestMethod() public Object doSomething(RestLogger logger) {...}

If your resource extends from {@link oajr.RestServlet}, you can also use and override the following methods: