How to set the log level to be displayed in the release version of orhanobut / logger

Overview

orhanobut / logger is a handy library for viewing logs on Android. This section describes how to set the log level to display only error logs in the release version.

Setting method

Definition of log level to display

Prepare a class that implements LogAdapter. BuildConfig.DEBUG will be false in the release version, so here we will not show anything other than error level logs in the release version.

public class MyLogAdapter implements LogAdapter {
    @Override
    public void v(String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.v(tag, message);
        }
    }

    @Override
    public void d(String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.d(tag, message);
        }
    }

    @Override
    public void i(String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.i(tag, message);
        }
    }

    @Override
    public void w(String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.w(tag, message);
        }
    }

    @Override
    public void e(String tag, String message) {
        Log.e(tag, message);
    }

    @Override
    public void wtf(String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.wtf(tag, message);
        }
    }
}

Logger initialization

In Application etc., initialize Logger and set MyLogAdapter.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        Logger.init(getString(R.string.app_name)).logAdapter(new MyLogAdapter());
    }
}

Try using it!

Logger.d("Displayed only debug build");

The following is an example of output when using Logger. Only the debug version is output.

image1

sample

I have a project that works on Logger @ github.

Recommended Posts

How to set the log level to be displayed in the release version of orhanobut / logger
How to set the indent to 2 single-byte spaces in the JAXB implementation of the JDK
How to check the latest version of io.spring.platform to describe in pom.xml of Spring (STS)
How to set environment variables in the properties file of Spring boot application
How to set the display time to Japan time in Rails
How to download the old version of Apache Tomcat
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
Summary of how to use the proxy set in IE when connecting with Java
How to set chrony when the time shifts in CentOS7
How to derive the last day of the month in Java
[Rails] Where to be careful in the description of validation
How to set the IP address and host name of CentOS8
Fix the file name of war to the one set in Maven
How to get the id of PRIMAY KEY auto_incremented in MyBatis
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
How to set Lombok in Eclipse
[Rails] How to reset the database in production environment (Capistrano version)
About the log level of java.util.logging.Logger
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
How to set an image in the drawable Left / Right of a button using an icon font (Iconics)
Java-database connection Java-MySQL connection ③-2: How to set CLASSPATH to the build bus of Eclipse (Pleiades All in One) / September 2017
How to change the maximum and maximum number of POST data in Spark
How to find out the Java version of a compiled class file
How to find the total number of pages when paging in Java
How to get the value after "_" in Windows batch like Java -version
How to constrain the action of the transition destination when not logged in
How to change the value of a variable at a breakpoint in intelliJ
How to get the absolute path of a directory running in Java
[Swift] How to set an image in the background without using UIImageView.
Android development, how to check null in the value of JSON object
How to determine the number of parallels
[Java] How to set the Date time to 00:00:00
How to sort the List of SelectItem
How to install the legacy version [Java]
How to get the date in java
[Swift] How to get the number of elements in an array (super basic)
Possibility when deploying to EC2 but nothing is displayed in the error log
graphql-ruby: How to get the name of query or mutation in controller Note
How to get the ID of a user authenticated with Firebase in Swift
Summarize the life cycle of Java objects to be aware of in Android development
[Swift] How to change the order of Bar Items in Tab Bar Controller [Beginner]
How to make a unique combination of data in the rails intermediate table
How to set when "The constructor Empty () is not visible" occurs in junit
The list of installed apps is not displayed in getPackageManager (Android11 ​​/ API level 30)
Summary of how to select elements in Selenium
[Order method] Set the order of data in Rails
How to find the cause of the Ruby error
How to check the logs in the Docker container
Customize how to divide the contents of Recyclerview
Set the time of LocalDateTime to a specific time
How to add sound in the app (swift)
How to get today's day of the week
Output of how to use the slice method
[Java] (for MacOS) How to set the classpath
How to use JQuery in js.erb of Rails6
How to display the result of form input
How to build the simplest blockchain in Ruby
[Java] How to get the authority of the folder
How to log in automatically when Ubuntu restarts
How to check Rails commands in the terminal