Sending Android Logs with Live Templates in IntelliJ IDEA & Android Studio

As professional developers we are constantly looking  for productive tips to save our precious time. IntelliJ IDEA comes with many tricks and shortcuts. One of them are Live Templates.

Live templates are predefined code fragments, which allow us to code faster and finally to become more productive. We can create our custom live templates and edit existing.

They are stored in the following location:

  • Windows:
    <your home directory>\.<product name><version number>\config\templates
  • Linux:
    ~\.<product name><version number>\config\templates
  • MacOS:
    ~/Library/Preferences/<product name><version number>/templates

To create new live templates we need to launch Settings and open Live Templates page. Then we can select template group or create new one. I chose second option and called my template group: “Android”.

Next add new template and fill fields as below. I decided for following naming convention: first letter – “l” (from Log), second letter – “d,e,i,w” (from Log type), third letter if exists – “t” (from TAG, if it is defined).

  • Abbreviation: ld
  • Desription: Sends DEBUG log message
  • Template text:
  • Applicable in Java: statement

I also added another template for logs with defined TAG as static (abbreviation with “t” suffix, e.g. ldt, let):

  • Abbreviation: ldt
  • Desription: Sends DEBUG log message
  • Template text:
  • Applicable in Java: statement

Same convention I used for ERROR logs:

  • Abbreviation: le
  • Desription: Sends ERROR log message
  • Template text:
  • Applicable in Java: statement

and with static TAG:

  • Abbreviation: let
  • Desription: Sends ERROR log message
  • Template text:
  • Applicable in Java: statement

Finally it should look as below:

Zrzut ekranu 2014-05-21 o 21.52.21

In code it works perfectly:

Zrzut ekranu 2014-05-21 o 22.14.08

Zrzut ekranu 2014-05-21 o 22.16.10

Zrzut ekranu 2014-05-21 o 22.16.49

Zrzut ekranu 2014-05-21 o 22.17.01

I am also attaching Android.xml file from Live Templates directory so you can faster add templates I created above. I was a bit lazy, but you can add relevant templates for other log types (e.g. info, verbose, warn).

More about Live Templates you can find here.