3

How do I increase the size of /dev/log/main by a factor of 10? My understanding is the log has a fixed size (16K?) and rolls over when that limit is reached. I'd like to find out what the log size is currently set at and increase it by a lot.

I'm debugging an issue that occurs infrequently when the device hasn't been used for a long period of time (maybe an hour?). I've instrumented the code with log messages so I can understand what is happening when the bug occurs.

My problem is my instrumentation causes the log to roll over in about 2 minutes. I would like to increase the size of dev/log/main by a factor of 10 if possible.

  • I presume that leaving it connected to the computer with adb logcat > my_log_file.log running isn't an option? – Kevin M Dec 29 '11 at 22:00
3

To find out the actual size of the ring buffer, you can use

$ adb logcat -g

To adjust the size of the ring buffer, you might try

$ adb logcat -r <kbytes>

At least that's what some tutorials say. For more details, you might want to read "adb logcat" Command Options and Log Buffers.

P.S.: I guess those settings (manual adjusted ring buffer size) will not survive a reboot -- just to consider.

| improve this answer | |
  • actually it needs tp be adb logcat -r 100000 -f sdcard/log.log . -f is required. – Aftershock Sep 13 '13 at 18:39
  • 1
    I dont think -r is useful as from reading the logcat manual, it will set the size at which the logcat tool will rotate the file it is writing out to using the "-f" option and NOT the size of the in-memory ring buffer used by the logger kernel module! – Maks Feb 25 '14 at 2:59
3

If you're looking to change the default size for a log buffer, to persist between reboots, you can recompile the kernel with updated buffer sizes.

The file containing log buffer definitions is:

<kernel>/drivers/staging/android/logger.c

The versions I'm looking at use a macro to define log buffers in that file:

DEFINE_LOGGER_DEVICE(variable, name, size)

There will likely be a number of loggers; "main" is usually the one you're looking for.

| improve this answer | |
  • This should be known on all the related questions here and on stackoverflow ! Nice find. Of note, Main and System are the default logcat buffers. You'd probably want to increase them both. Well, depending on if your Android version uses them. See logcat -g and logcat -h – cde Jan 12 '14 at 9:58
2

Starting with Android 5, the in-kernel logger driver is deprecated which exposed the ring buffers through /dev/log/* character devices. Instead a userspace logging daemon named logd manages buffers “main”, “system”, “radio”, “events”, and “crash”. Optional buffers “security” (e.g. for adb shell/push/pull logging) and on userdebug builds “kernel” (for klogd) and “stats” (for logs statistics) were added later. logd mainly covers the functionality of its desktop counterpart syslogd, but also includes klogd and partially auditd to get logs from SELinux subsystem of kernel. Behavior of logging daemon is controlled through different properties.

Apps and native processes write their logs to relevant buffers through socket /dev/socket/logdw (by making use of liblog functions). logcat command reads the buffers from /dev/socket/logdr while controls the daemon and buffers through /dev/socket/logd socket. Use -g/-G options to get and set size of individual buffers:

  -g, --buffer-size
                  Get the size of the ring buffer.
  -G <size>, --buffer-size=<size>
                  Set size of log ring buffer, may suffix with K or M.

There's also an option in Developer Options: Logger buffer sizes (which also sets property persist.logd.size) to set same size for all buffers.

persist.logd.size is read from /data/property/ which isn't available unless /data is mounted and decrypted (in case of FDE). But sometimes buffers may overflow even before that, so the solution is to set ro.logd.size (through default.prop/build.prop or directly in some *.rc file) before the logd service is started.

| improve this answer | |
  • Thank you very much for that tip about increasing the size of the buffer persistently between boots! It was very useful while debugging a timing error that occurred before I could adjust the size. – Nonny Moose Mar 1 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.