This topic describes how to use MaxCompute SDK for Java to return error logs.


MaxCompute SDK for Java provides the abstract class RetryLogger. For more information, see the MaxCompute SDK for Java documentation.
public static abstract class RetryLogger {
 * The callback function that enables RestClient to retry after an error occurs.
 * @param e
 *     The error.
 * @param retryCount
 *     The number of retries.
 * @param retrySleepTime
 *     The retry interval.
public abstract void onRetryLog(Throwable e, long retryCount, long retrySleepTime);

You can create a RetryLogger subclass and use odps.getRestClient().setRetryLogger(new UserRetryLogger()); to return logs when the system initializes MaxCompute objects.


// init odps
odps.getRestClient().setRetryLogger(new UserRetryLogger());
// your retry logger
public class UserRetryLogger extends RetryLogger {
 public void onRetryLog(Throwable e, long retryCount, long sleepTime) {
   if (e != null && e instanceof OdpsException) {
     String requestId = ((OdpsException) e).getRequestId();
             if (requestId != null) {
           "Warning: ODPS request failed, requestID:%s, retryCount:%d, will retry in %d seconds.", requestId, retryCount, sleepTime));
       "Warning: ODPS request failed:%s, retryCount:%d, will retry in %d seconds.", e.getMessage(), retryCount, sleepTime));