summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2014-10-02 13:12:28 -0500
committerMark Salyzyn2015-02-09 16:12:59 -0600
commit956870518ee89b5302b8409ac78f287bf091d9ed (patch)
treea6b832d88bf2871e6a7fe59be7108da1561ab08a /liblog/log_is_loggable.c
parent3bc8ae63ce3bbcc0ab61def99a4e9b4822ba3f51 (diff)
downloadplatform-system-core-956870518ee89b5302b8409ac78f287bf091d9ed.tar.gz
platform-system-core-956870518ee89b5302b8409ac78f287bf091d9ed.tar.xz
platform-system-core-956870518ee89b5302b8409ac78f287bf091d9ed.zip
liblog: add __android_log_is_loggable()
- Add new liblog API __android_log_is_loggable(prio, tag, def) - future plan to integrate this into the runtime checks and into the logd daemon for filtration. Inert for now. Bug: 17760225 Change-Id: I16395b4d42acc08f0209f55a1cbf87b0b2112898
Diffstat (limited to 'liblog/log_is_loggable.c')
-rw-r--r--liblog/log_is_loggable.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c
new file mode 100644
index 000000000..df671234c
--- /dev/null
+++ b/liblog/log_is_loggable.c
@@ -0,0 +1,69 @@
1/*
2** Copyright 2014, The Android Open Source Project
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8** http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17#include <ctype.h>
18#include <string.h>
19#include <sys/system_properties.h>
20
21#include <android/log.h>
22
23static int __android_log_level(const char *tag, int def)
24{
25 char buf[PROP_VALUE_MAX];
26
27 if (!tag || !*tag) {
28 return def;
29 }
30 {
31 static const char log_namespace[] = "log.tag.";
32 char key[sizeof(log_namespace) + strlen(tag)];
33
34 strcpy(key, log_namespace);
35 strcpy(key + sizeof(log_namespace) - 1, tag);
36
37 if (__system_property_get(key + 8, buf) <= 0) {
38 buf[0] = '\0';
39 }
40 }
41 switch (toupper(buf[0])) {
42 case 'V': return ANDROID_LOG_VERBOSE;
43 case 'D': return ANDROID_LOG_DEBUG;
44 case 'I': return ANDROID_LOG_INFO;
45 case 'W': return ANDROID_LOG_WARN;
46 case 'E': return ANDROID_LOG_ERROR;
47 case 'F': /* FALLTHRU */ /* Not officially supported */
48 case 'A': return ANDROID_LOG_FATAL;
49 case 'S': return -1; /* ANDROID_LOG_SUPPRESS */
50 }
51 return def;
52}
53
54int __android_log_is_loggable(int prio, const char *tag, int def)
55{
56 static char user;
57 int logLevel;
58
59 if (user == 0) {
60 char buf[PROP_VALUE_MAX];
61 if (__system_property_get("ro.build.type", buf) <= 0) {
62 buf[0] = '\0';
63 }
64 user = strcmp(buf, "user") ? -1 : 1;
65 }
66
67 logLevel = (user == 1) ? def : __android_log_level(tag, def);
68 return logLevel >= 0 && prio >= logLevel;
69}