Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | |
Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 17 | #include <stdlib.h> |
Elliott Hughes | 4126c12 | 2014-07-23 11:38:38 -0700 | [diff] [blame] | 18 | #include <syslog.h> |
Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 19 | |
| 20 | #include "private/libc_logging.h" |
| 21 | |
| 22 | static const char* syslog_log_tag = NULL; |
| 23 | static int syslog_priority_mask = 0xff; |
| 24 | |
| 25 | void closelog() { |
Elliott Hughes | 4126c12 | 2014-07-23 11:38:38 -0700 | [diff] [blame] | 26 | syslog_log_tag = NULL; |
Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void openlog(const char* log_tag, int /*options*/, int /*facility*/) { |
| 30 | syslog_log_tag = log_tag; |
| 31 | } |
| 32 | |
| 33 | int setlogmask(int new_mask) { |
| 34 | int old_mask = syslog_priority_mask; |
| 35 | // 0 is used to query the current mask. |
| 36 | if (new_mask != 0) { |
| 37 | syslog_priority_mask = new_mask; |
| 38 | } |
| 39 | return old_mask; |
| 40 | } |
| 41 | |
| 42 | void syslog(int priority, const char* fmt, ...) { |
| 43 | va_list args; |
| 44 | va_start(args, fmt); |
| 45 | vsyslog(priority, fmt, args); |
| 46 | va_end(args); |
| 47 | } |
| 48 | |
Christopher Ferris | bc74ecf | 2014-07-23 18:05:58 -0700 | [diff] [blame] | 49 | void vsyslog(int /*priority*/, const char* /*fmt*/, va_list /*args*/) { |
| 50 | // HACK to avoid lock up on certain devices. This will be reverted when |
| 51 | // that is fixed. |
| 52 | #if 0 |
Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 53 | // Check whether we're supposed to be logging messages of this priority. |
| 54 | if ((syslog_priority_mask & LOG_MASK(LOG_PRI(priority))) == 0) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // What's our log tag? |
| 59 | const char* log_tag = syslog_log_tag; |
| 60 | if (log_tag == NULL) { |
| 61 | log_tag = getprogname(); |
| 62 | } |
| 63 | |
| 64 | // What's our Android log priority? |
| 65 | priority &= LOG_PRIMASK; |
| 66 | int android_log_priority; |
Elliott Hughes | 4126c12 | 2014-07-23 11:38:38 -0700 | [diff] [blame] | 67 | if (priority <= LOG_ERR) { |
Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 68 | android_log_priority = ANDROID_LOG_ERROR; |
| 69 | } else if (priority == LOG_WARNING) { |
| 70 | android_log_priority = ANDROID_LOG_WARN; |
| 71 | } else if (priority <= LOG_INFO) { |
| 72 | android_log_priority = ANDROID_LOG_INFO; |
| 73 | } else { |
| 74 | android_log_priority = ANDROID_LOG_DEBUG; |
| 75 | } |
| 76 | |
| 77 | __libc_format_log_va_list(android_log_priority, log_tag, fmt, args); |
Christopher Ferris | bc74ecf | 2014-07-23 18:05:58 -0700 | [diff] [blame] | 78 | #endif |
Elliott Hughes | b766136 | 2014-07-21 16:35:24 -0700 | [diff] [blame] | 79 | } |