LoginSignup
1
2

More than 1 year has passed since last update.

Robolectric で android.util.Log の出力先を変える

Last updated at Posted at 2016-04-29

標準出力に流す方法

についてはググるとすぐに見つかる

ShadowLog.stream = System.out;

参考

のだけど、
テストの出力結果がさっぱり読めなくなるのでこれでは幸せになれない…

ファイルに出力する方法

については直に FileOutputStream から PrintStream を作れば OK

ShadowLog.stream = new PrintStream(
  new FileOutputStream("hoge.log"), true)

これで tail -f も grep もやりたい放題。
ステキ!

備考

よく使うやつを参考までに。

ERROR と WARN のみを出力

Log.DEBUG や Log.VERBOSE などが邪魔な場合につかう

tail -f your-project/hoge.log | egrep --line-buffered "(E/|W/)" 

ERROR のみを 10 行出力

たとえばスタックトレースを表示したい場合

tail -f your-project/hoge.log | egrep -A10 --line-buffered "(E/)" 

前後の行が必要であれば -A10 -B10 のように指定する

以上

快適なログ出力ライフを!

1
2
0

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
1
2