10

Is it possible to set the log levels on a device that is not rooted? so I want to change the device log level somehow to "debug". is this something that can be done?

since its not rooted i dont think setprop will work. i can also not change the local.prop file since i do not have permissions to do so.

other than maybe getting lucky and finding a hidden menu that has the log levels in it. is there a way for me to enhance the log level some other way?

thanks for the help.

Dave Powell
  • 671
  • 5
  • 14
  • 26
  • what "device log level"? And setprop is not limited to rooted phones afaik ( minus read-only properties ) – zapl Apr 23 '12 at 22:41
  • what i am noticing is on non rooted devices there are properties that are either missing from the android system properties or one is not allowed to use setprop to modify those properties. in other words, setprop command works but the changes dont stick. Thus, is there another way to set the log level on this particular android device? all in all, if a normal android device has log levels set to say "info" can I change those log levels to say "debug"? – Dave Powell Apr 24 '12 at 04:02

2 Answers2

14

setprop:

  • is temporary until you reboot your device, even on rooted phones.
  • you can persist properties through reboots if you write them into local.prop which is only possible on rooted phones.
  • some properties are read-only and can only be changed if you change some init files. That might be even impossible on rooted phones.
  • each device (or firmware) can have a different set of properties. A rooted phone wouldn't have automatically more.

Loglevels:

  • If the code that prints the log says Log.d() then it will be on "debug" level and you can't change that unless you change the code and recompile it. There is nothing that hides log messages if you execute a Log.? regardless of level.
  • the Android framework hides some log messages if you have a release build of your firmware. To show those you need to recompile your firmware as debug build. No chance to get those to show on a rooted phone either.
  • some messages are controlled by a local variable in the code like if (LOCAL_LOGV) Log.v(... - you need to change the code here to see those too.
  • some messages are controlled by Config.LOGV (= always false) see Config. No way to change the broken behaviour here either. You need to recompile.
  • some other logmessages are hidden until you enable a property:

example

public static final boolean DEBUG_SQL_CACHE =
Log.isLoggable("SQLiteCompiledSql", Log.VERBOSE); 

// somewhere in code
if (SQLiteDebug.DEBUG_SQL_CACHE) {
    Log.d(TAG, "secret message!");
}

if you do adb shell setprop log.tag.SQLiteCompiledSql VERBOSE you should see those messages popping up. Log#isLoggable()

There is no global loglevel I know of.

zapl
  • 63,179
  • 10
  • 123
  • 154
  • first of all thanks for the 411. I really appreciate it. I guess is there a way to find out what the log level is set to? for a particular application on the device for example what the manufacturer uses for to call the UI menu. Then use setprop on that UI menu call to set it to verbose? finally using logcat to then see all the error conditions for that particular UI menu? – Dave Powell Apr 24 '12 at 12:28
  • If you have access to the sourcecode of the app (or the apk + a [decompiler](http://stackoverflow.com/questions/1249973/decompiling-dex-into-java-sourcecode)) then you can check if there is logging that can be enabled e.g. through `setprop` - You could even try to edit the sourcecode with [apktool](http://code.google.com/p/dex2jar/wiki/ModifyApkWithDexTool) and add some logging yourself. Or you could use DDMS (you may need to make the app [debuggable](http://developer.android.com/guide/topics/manifest/application-element.html#debug) with apktool). But there is no general approach to enable log – zapl Apr 24 '12 at 12:56
  • even if i was able to do that i could not get that app in the device since its not rooted. i know in come cases manufacturers leave debug log levels on their device for trouble shooing network field testing and i assume since they use log.d all over the place when they enable logging it is just this debug level that is enabled. i guess i would be out of luck in terms of even checking the status to see what level of logs are being made available unless i go into each apk like you said and check it individually which would suck hard. – Dave Powell Apr 24 '12 at 13:03
  • There is init loglevel (http://elinux.org/Android_Debugging), which could be a good candidate for a "global loglevel", as init stays up after boot and it's loglevel settings affect all services. – ogurets Jun 13 '17 at 20:41
3

Let me suggest a tiny replacement for the standard log class (I'm the author)

https://github.com/zserge/log

It's backwards compatible, so you only need to modify your imports. Then you can set the minimal log level for your app via Log.level(Log.D) or Log.level(Log.W) etc, or you can disable logs using Log.useLog(false). No need to modify your existing logging code.

Despite of its small size this logger works with both, JVM and Android, allows you to skip the "tag" parameter, simplifies logging of multiple values separated by commas or using a format string. So it's really convenient, easy to migrate to, and only adds ~4 kilobytes to your APK size.

zserge
  • 2,212
  • 2
  • 31
  • 40