[JAVA] Make Log of Android Studio / Xcode convenient

Introduction

I will introduce the log output in Android Studio / Xcode because it will be convenient with a little ingenuity.

In particular

Aim for that.

environment

Android Studio

Open Live Templates from Preferences and define a new template in Android Log from the + button on the right.

Abbreviation is the string that calls the template, Description is the description of the template, and Template Text is the string that is actually output. From the Define below it, set when to enable this Live Template. For the time being, you should just check Java-> Statement.

Now, what to enter in Template Text, you can define a variable by enclosing it in $. Since the defined variables can be edited from Edit variables, the class name etc. should be inserted automatically as shown below.

Now you can write Log.d () with the class name, function name, etc. inserted by just entering ld!

Xcode

First, define a class for log output so that the class name etc. will be inserted automatically. The variable file looks like/Users/[username] /Desktop/hoge/huga/ViewController.swift, so only the file name is cut out.

MyUtility.swift


class MyUtility {
    class func logD(tag: String, file: String, function: String, log: String) {
        NSLog("D/\(tag): \(URL(string: file)!.deletingPathExtension().lastPathComponent)#\(function): \(log)")
    }
}

Then use Code Snippet to do the input automatically. Open the Snippets list from the + button at the top right of the window and set as follows.

Since the file name and function name are automatically entered in # file and # function, this is assigned to the function for log output earlier. Variable parts such as TAG and Log should be placedholders as <# TAG #>.

Now, just like Android Studio, you can write the output of the log with the class name, function name, etc. inserted by just typing ld!

Reference link

Recommended Posts

Make Log of Android Studio / Xcode convenient
Make an executable jar using Android Studio
Notes in Android studio
Defeating Android Studio Part 3-6
Defeating Android Studio Part 1 & Part 2
Definition of Android constants
How to make an app using Tensorflow with Android Studio