Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable logging in external library

I am using retrofit library from square(added as a jar dependency), which has a logger configured. (link)

  private static final Logger LOGGER = Logger.getLogger(RestAdapter.class.getName());

How can I enable logging in this library (from my application).

I see check like this

if (LOGGER.isLoggable(Level.FINE)) {
          logResponseBody(url, body, statusCode, elapsedTime);
        }

so it looks like, I may have to get this logger and set the log level. Or does java logger read loglevel setting from config file, environment, class path ??

I am not familiar with java platform. Any help to log the messages from this (external) library in console is appreciated. For example, I need to see all the log message from this class (RestAdapter) in my android console / logCat (which is set at verbose level).

thanks.

EDIT 1:

I added the below to my entry point, and I could see it is been called. Still no relavent log

static final String LOGGER_NAME = "retrofit.http.RestAdapter";

@Override
    public void onCreate() {
        super.onCreate();
        Logger mLoggerInstance = Logger.getLogger(LOGGER_NAME);
        if (mLoggerInstance != null) {
            mLoggerInstance.setLevel(Level.FINE);
        }
    }

EDIT 2:

I edited the external library to change reference of loglevel FINE to DEBUG. THis let me see the log, still wonder the same effect can be achieved through logger configuration alone.

I see a post here, but didn't work. Logging with Logger under Android

Not certain, but it looks like the debug level below Debug is suppressed in Android. (source)

like image 920
bsr Avatar asked May 15 '26 22:05

bsr


1 Answers

This is Java Logging API. By default it uses global jre/lib/logging.properties config file. You can copy it to your application folder, change it and pass it as java arg

java -Djava.util.logging.config.file=logging.properties ...

read Oracle's overview http://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html or this article http://tutorials.jenkov.com/java-logging/configuration.html for mmore details

like image 62
Evgeniy Dorofeev Avatar answered May 18 '26 12:05

Evgeniy Dorofeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!