Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 1 | /* |
| 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 Salyzyn | 5ae7c34 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 19 | #include <log/log.h> |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 20 | |
| 21 | #include "log_portability.h" |
| 22 | |
| 23 | /* In the future, we would like to make this list extensible */ |
Mark Salyzyn | a2d59f8 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 24 | static const char* LOG_NAME[LOG_ID_MAX] = { |
| 25 | /* clang-format off */ |
| 26 | [LOG_ID_MAIN] = "main", |
| 27 | [LOG_ID_RADIO] = "radio", |
| 28 | [LOG_ID_EVENTS] = "events", |
| 29 | [LOG_ID_SYSTEM] = "system", |
| 30 | [LOG_ID_CRASH] = "crash", |
| 31 | [LOG_ID_SECURITY] = "security", |
| 32 | [LOG_ID_KERNEL] = "kernel", |
| 33 | /* clang-format on */ |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
Mark Salyzyn | a2d59f8 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 36 | LIBLOG_ABI_PUBLIC const char* android_log_id_to_name(log_id_t log_id) { |
| 37 | if (log_id >= LOG_ID_MAX) { |
| 38 | log_id = LOG_ID_MAIN; |
| 39 | } |
| 40 | return LOG_NAME[log_id]; |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Mark Salyzyn | a2d59f8 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 43 | LIBLOG_ABI_PUBLIC log_id_t android_name_to_log_id(const char* logName) { |
| 44 | const char* b; |
| 45 | int ret; |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 46 | |
Mark Salyzyn | a2d59f8 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 47 | if (!logName) { |
| 48 | return -1; /* NB: log_id_t is unsigned */ |
| 49 | } |
| 50 | b = strrchr(logName, '/'); |
| 51 | if (!b) { |
| 52 | b = logName; |
| 53 | } else { |
| 54 | ++b; |
| 55 | } |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 56 | |
Mark Salyzyn | a2d59f8 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 57 | for (ret = LOG_ID_MIN; ret < LOG_ID_MAX; ++ret) { |
| 58 | const char* l = LOG_NAME[ret]; |
| 59 | if (l && !strcmp(b, l)) { |
| 60 | return ret; |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 61 | } |
Mark Salyzyn | a2d59f8 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 62 | } |
| 63 | return -1; /* should never happen */ |
Mark Salyzyn | e188bd9 | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 64 | } |