ログレベルについて軽く調べたところによると、特にマニュフェストファイルの
1 | < application android:debuggable> |
属性に連動しているわけではないという事がわかった。
知らないうちにLog.d()などを沢山埋めている場合、
1 | < application android:debuggable = "false" > |
にしたところで、勝手に抑止されるわけではないので、以下のようなクラスを用意すると良いだろう。
06 | public static void i( final String tag, final String msg) { |
10 | public static void i( final String tag, final String msg, final Throwable th) { |
13 | android.util.Log.i(tag, msg); |
16 | android.util.Log.i(tag, msg, th); |
20 | public static void d( final String tag, final String msg) { |
24 | public static void d( final String tag, final String msg, final Throwable th) { |
25 | if (!AppMan.DEBUG_MODE) { |
29 | android.util.Log.d(tag, msg); |
31 | android.util.Log.d(tag, msg, th); |
35 | public static void e( final String tag, final String msg) { |
39 | public static void e( final String tag, final String msg, final Throwable th) { |
42 | android.util.Log.e(tag, msg); |
44 | android.util.Log.e(tag, msg, th); |
48 | public static void w( final String tag, final String msg) { |
52 | public static void w( final String tag, final String msg, final Throwable th) { |
55 | android.util.Log.w(tag, msg); |
57 | android.util.Log.w(tag, msg, th); |
61 | public static void v( final String tag, final String msg) { |
65 | public static void v( final String tag, final String msg, final Throwable th) { |
66 | if (!AppMan.DEBUG_MODE) { |
70 | android.util.Log.v(tag, msg); |
72 | android.util.Log.v(tag, msg, th); |
後は、各クラスでeclipseの ctrl + shift + o でimport定義を更新して、上記クラスを利用するようにすれば、簡単にマニュフェストファイルに連動して抑止する事ができる。
ただし、上記ソースを見て頂ければわかると思いますが、AppMan.DEBUG_MODE がマニュフェストファイルと連動していなくてはならない。
アプリケーション起動の際、この定数をマニュフェストファイルを参照して初期化する必要がある。
マニュフェストファイルの android:debuggable 属性を参照するコードは以下。
05 | public static boolean isDebugAble(Context ctx){ |
06 | PackageManager manager = ctx.getPackageManager(); |
07 | ApplicationInfo appInfo = null ; |
09 | appInfo = manager.getApplicationInfo(ctx.getPackageName(), 0 ); |
10 | } catch (NameNotFoundException e) { |
14 | if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE) return true ; |
このソースは以下から貰いました。ありがとうございます。
http://www.taosoftware.co.jp/blog/2009/03/android_apireleasedebug.html
後は、アプリケーション起動時、一番最初に表示されるActivityなどで、独自のAppManクラスのDEBUG_MODE定数に上記ユーティリティの戻り値をセットすれば良い。
0 件のコメント:
コメントを投稿