LoginSignup
6
4

More than 5 years have passed since last update.

Kotlin Androidでログ(Logcat)が出力されないときの対処法

Last updated at Posted at 2018-10-01

概要

Androidスマートフォン向けアプリケーション開発にて、コード中に記載した Log.d(TAG, props) のようなログ出力が表示されないときの対処法を以下に示す。

検証環境

  • Android Studio 3.1.4
  • macOS Sierra バージョン10.12.6

原因

Logが出力されない原因は、  Log.d(TAG, props)props 変数が null だから。

対策

Log.d(TAG, "props: " + props) の様に文字列連結して、 Log.d() の第二引数が null とならないようにしたら、 propsnull のときもログ出力される。

【追記】
コメント欄にて、 @SorrowBlue さんにご指摘いただきました。

Log.d("TAG", "$props")

という具合に、変数展開すると、nullの時は"null"と出力されるようです。
文字列連結よりも便利ですね。👏

備考

業務で使うのなら、標準ライブラリである android.util.Log をラップしたclassをつくって、nullならnullと出力したり、envによって出力を出し分けたりなどするほうが親切でいいかも。

6
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4