How to diagnose log log function error, that is when negative value is returned:
/*
* Send a formatted string to the log, used like printf(fmt,...)
*/
int __android_log_print(int prio, const char *tag, const char *fmt, ...);
Thank you!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Short answer: check errno.
Long answer: There appear two reasons __android_log_print can return a negative value. The first is if it’s unable to open any of the log files for writing (/dev/log/main, /dev/log/radio, or /dev/log/events). The second is if the write() system call returns a negative number.
After __android_log_print returns a negative value, is errno set? If so, its value should give you some information about what went wrong. If errno is zero, your log call probably wound up in __write_to_log_null and you should investigate your program’s ability to open those /dev/log files.
If errno is set, it’s possible that it was set when trying to open the log files. You should be able to isolate this case by setting errno = 0, then calling __android_log_bug_write with a bad log_id (first argument). For this to be useful, it’ll need to be the first call to any of the logging functions – otherwise the file opening stage will have been and gone. Obviously this is only necessary if errno is set to something that could have been at write time or at open time.
This answer comes to you courtesy of system/core/liblog/logd_write.c.