|
25 | 25 | #include <stdlib.h>
|
26 | 26 | #include <stdarg.h>
|
27 | 27 |
|
| 28 | +#ifdef MOTOROLA_LOG |
| 29 | +#if HAVE_LIBC_SYSTEM_PROPERTIES |
| 30 | +#include <sys/system_properties.h> |
| 31 | +#endif |
| 32 | +#endif |
| 33 | + |
28 | 34 | #include <cutils/logger.h>
|
29 | 35 | #include <cutils/logd.h>
|
30 | 36 | #include <cutils/log.h>
|
@@ -87,6 +93,96 @@ int __htclog_print_private(int a1, const char *a2, const char *fmt, ...)
|
87 | 93 | }
|
88 | 94 | #endif
|
89 | 95 |
|
| 96 | +#ifdef MOTOROLA_LOG |
| 97 | +/* Fallback when there is neither log.tag.<tag> nor log.tag.DEFAULT. |
| 98 | + * this is compile-time defaulted to "info". The log startup code |
| 99 | + * looks at the build tags to see about whether it should be DEBUG... |
| 100 | + * -- just as is done in frameworks/base/core/jni/android_util_Log.cpp |
| 101 | + */ |
| 102 | +static int prio_fallback = ANDROID_LOG_INFO; |
| 103 | + |
| 104 | +/* |
| 105 | + * public interface so native code can see "should i log this" |
| 106 | + * and behave similar to java Log.isLoggable() calls. |
| 107 | + * |
| 108 | + * NB: we have (level,tag) here to match the other __android_log entries. |
| 109 | + * The Java side uses (tag,level) for its ordering. |
| 110 | + * since the args are (int,char*) vs (char*,char*) we won't get strange |
| 111 | + * swapped-the-strings errors. |
| 112 | + */ |
| 113 | + |
| 114 | +#define LOGGING_PREFIX "log.tag." |
| 115 | +#define LOGGING_DEFAULT "log.tag.DEFAULT" |
| 116 | + |
| 117 | +int __android_log_loggable(int prio, const char *tag) |
| 118 | +{ |
| 119 | + int nprio; |
| 120 | + |
| 121 | +#if HAVE_LIBC_SYSTEM_PROPERTIES |
| 122 | + char keybuf[PROP_NAME_MAX]; |
| 123 | + char results[PROP_VALUE_MAX]; |
| 124 | + int n; |
| 125 | + |
| 126 | + /* we can NOT cache the log.tag.<tag> and log.tag.DEFAULT |
| 127 | + * values because either one can be changed dynamically. |
| 128 | + * |
| 129 | + * damn, says the performance compulsive. |
| 130 | + */ |
| 131 | + |
| 132 | + n = 0; |
| 133 | + results[0] = '\0'; |
| 134 | + if (tag) { |
| 135 | + memcpy (keybuf, LOGGING_PREFIX, strlen (LOGGING_PREFIX) + 1); |
| 136 | + /* watch out for buffer overflow */ |
| 137 | + strncpy (keybuf + strlen (LOGGING_PREFIX), tag, |
| 138 | + sizeof (keybuf) - strlen (LOGGING_PREFIX)); |
| 139 | + keybuf[sizeof (keybuf) - 1] = '\0'; |
| 140 | + n = __system_property_get (keybuf, results); |
| 141 | + } |
| 142 | + if (n == 0) { |
| 143 | + /* nothing yet, look for the global */ |
| 144 | + memcpy (keybuf, LOGGING_DEFAULT, sizeof (LOGGING_DEFAULT)); |
| 145 | + n = __system_property_get (keybuf, results); |
| 146 | + } |
| 147 | + |
| 148 | + if (n == 0) { |
| 149 | + nprio = prio_fallback; |
| 150 | + } else { |
| 151 | + switch (results[0]) |
| 152 | + { |
| 153 | + case 'E': |
| 154 | + nprio = ANDROID_LOG_ERROR; |
| 155 | + break; |
| 156 | + case 'W': |
| 157 | + nprio = ANDROID_LOG_WARN; |
| 158 | + break; |
| 159 | + case 'I': |
| 160 | + nprio = ANDROID_LOG_INFO; |
| 161 | + break; |
| 162 | + case 'D': |
| 163 | + nprio = ANDROID_LOG_DEBUG; |
| 164 | + break; |
| 165 | + case 'V': |
| 166 | + nprio = ANDROID_LOG_VERBOSE; |
| 167 | + break; |
| 168 | + case 'S': |
| 169 | + nprio = ANDROID_LOG_SILENT; |
| 170 | + break; |
| 171 | + default: |
| 172 | + /* unspecified or invalid */ |
| 173 | + nprio = prio_fallback; |
| 174 | + break; |
| 175 | + } |
| 176 | + } |
| 177 | +#else |
| 178 | + /* no system property routines, fallback to a default */ |
| 179 | + nprio = prio_fallback; |
| 180 | +#endif |
| 181 | + |
| 182 | + return ((prio >= nprio) ? 1 : 0); |
| 183 | +} |
| 184 | +#endif |
| 185 | + |
90 | 186 | static int __write_to_log_null(log_id_t log_fd, struct iovec *vec, size_t nr)
|
91 | 187 | {
|
92 | 188 | return -1;
|
|
0 commit comments