Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: java.util.logging.Logger vs android.util.Log

Why does Android maintain 2 different Log classes that seem to support the same things?

I'm talking about:

  1. Log android.util.Log
  2. Logger java.util.logging.Logger

For what I've seen for some years developing, every Android official documentation points to the Log and not the Logger.

Even specific loggers like the TimingLogger uses the Log.


So why are those 2 supported?

Are there any feature that can be used through Logger than I can't achieve through Log?

Are there specific use cases for both?

like image 833
neteinstein Avatar asked Mar 24 '17 11:03

neteinstein


People also ask

Which is the best logging framework in Java?

One of the most popular solutions for the Java world is the Apache Log4j 2 framework.

What is Java Util logger?

A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.

Does Java Util logging use Log4j?

The JDK Logging Adapter is a custom implementation of java. util. logging. LogManager that uses Log4j.

How many types of logs are there in Android?

The four Android log buffers are main, events, radio and system. The main log is for the application, events is for system event information, radio is for phone-related information and system is low-level system messages and debugging.


1 Answers

The feature crossover seems to be:

  1. android.util.Log = java.util.logging.Logger
  2. android.util.Printer = java.util.logging.Formatter
  3. android.util.PrintStreamPrinter = java.util.logging.StreamHandler

Seems like "android.util.Log" is going to have:

  1. Support for android log.
  2. Support for out to Streams, Writers, and Strings.
  3. Is going to be a smaller, lightweight, and probably faster.

Looks like "J.U.L" is going to have:

  1. Buffering of records with the java.util.logging.MemoryHandler. This is good for say when a SEVERE error occurs you can include the last 1000 records which may be at lower level.
  2. Filtering of records using java.util.logging.Filter. There are no out of box filters included but it does give more granularity over implementing this behavior in a android.util.Printer
  3. Out of box support for XML.
  4. Out of box support for Sockets.
  5. Support for 3rd party java.util.logging.Handler implementations.
like image 180
jmehrens Avatar answered Oct 05 '22 20:10

jmehrens