λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸ’š 개발/μ•ˆλ“œλ‘œμ΄λ“œ

[μ•ˆλ“œλ‘œμ΄λ“œ] PrettyFormatStrategy μ‚¬μš©ν•΄μ„œ μ •λ¦¬λœ 둜그 좜λ ₯ν•˜λŠ” 방법

by devshin.kr 2021. 4. 28.
728x90

PrettyFormatStrategy : λ™μž‘ν•˜λŠ” thread, callstack, messageκ°€ 예쁘게 λ‚˜μ˜¬ 수 μžˆλ‹€.

 

 

1) app gradle.build

dependencies {
    implementation 'com.orhanobut:logger:2.2.0'

 

 

2) importλŠ” Ctrl + Space ν•΄μ„œ μž‘μ•„ μ€˜λ„ λœλ‹€.

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

 

 

3) MainActivity > super.onCreate()

// Logger Stack Trace Count.
PrettyFormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder().methodCount(5).build();
// Remove Log Message When Release.
Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy){
@Override
   public boolean isLoggable(int priority, @Nullable String tag) {
      //return BuildConfig.DEBUG;
   return true;
   }
});

Logger.t("tag").d("onCreate");	// νƒœκ·Έ, 디버깅할 λ‚΄μš©
Logger.d("onCreate");	// 디버깅할 λ‚΄μš©

 

 

4) MainActivicy > onDestroy()

Logger.clearLogAdapters();

 

 

5) 둜그λ₯Ό 찍을 ν•¨μˆ˜ μ•ˆ

Logger.d(“찍고 싢은 둜그 λ‚΄μš©”);

 

 

κ²°κ³Ό 둜그 ) LogCat 에 μ•„λž˜μ™€ 같이 κΉ”λ”ν•˜κ²Œ μ°νžŒλ‹€.

 

 

 

 

 

 

ν…ŒμŠ€νŠΈν•œ 전체 μ½”λ“œ)

package com.devshin93.myapplication;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Logger Stack Trace Count.
        PrettyFormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder().methodCount(5).build();
        // Remove Log Message When Release.
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy){
            @Override
            public boolean isLoggable(int priority, @Nullable String tag) {
                //return BuildConfig.DEBUG;
                return true;
            }
        });

        Logger.t("Tag").d("λ‚΄μš©");
        Logger.d("onCreate");

        prettyTestFunc();   // ν…ŒμŠ€νŠΈ ν•¨μˆ˜ 호좜
    }

    @Override
    protected void onDestroy() {
        Logger.clearLogAdapters();  // 둜그 λ‚΄μš©μ„ μ§€μš΄λ‹€

        super.onDestroy();
    }

    /**
     * prettyFormatStrategy ν…ŒμŠ€νŠΈ ν•¨μˆ˜
      */
    public void prettyTestFunc() {
        Logger.d("prettyTestFunc!!");
    }
}

 

λŒ“κΈ€