blob: 479bbfeec34691db333afa76e642dc4f20cb4128 [file] [log] [blame]
Mark Salyzynfacf94c2016-03-01 13:45:42 -08001/*
2** Copyright 2013-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 <string.h>
18
Mark Salyzynaeaaf812016-09-30 13:30:33 -070019#include <log/log.h>
Mark Salyzynfacf94c2016-03-01 13:45:42 -080020
21#include "log_portability.h"
22
23/* In the future, we would like to make this list extensible */
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080024static const char* LOG_NAME[LOG_ID_MAX] = {
Stefan Lafon701a0652017-08-24 20:14:06 -070025 /* clang-format off */
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080026 [LOG_ID_MAIN] = "main",
27 [LOG_ID_RADIO] = "radio",
28 [LOG_ID_EVENTS] = "events",
29 [LOG_ID_SYSTEM] = "system",
30 [LOG_ID_CRASH] = "crash",
Stefan Lafon701a0652017-08-24 20:14:06 -070031 [LOG_ID_STATS] = "stats",
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080032 [LOG_ID_SECURITY] = "security",
33 [LOG_ID_KERNEL] = "kernel",
34 /* clang-format on */
Mark Salyzynfacf94c2016-03-01 13:45:42 -080035};
36
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080037LIBLOG_ABI_PUBLIC const char* android_log_id_to_name(log_id_t log_id) {
38 if (log_id >= LOG_ID_MAX) {
39 log_id = LOG_ID_MAIN;
40 }
41 return LOG_NAME[log_id];
Mark Salyzynfacf94c2016-03-01 13:45:42 -080042}
43
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080044LIBLOG_ABI_PUBLIC log_id_t android_name_to_log_id(const char* logName) {
45 const char* b;
46 int ret;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080047
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080048 if (!logName) {
49 return -1; /* NB: log_id_t is unsigned */
50 }
51 b = strrchr(logName, '/');
52 if (!b) {
53 b = logName;
54 } else {
55 ++b;
56 }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080057
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080058 for (ret = LOG_ID_MIN; ret < LOG_ID_MAX; ++ret) {
59 const char* l = LOG_NAME[ret];
60 if (l && !strcmp(b, l)) {
61 return ret;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080062 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080063 }
64 return -1; /* should never happen */
Mark Salyzynfacf94c2016-03-01 13:45:42 -080065}