syslog.cpp revision bc74ecfaf5de47056fd8a48db65c0e5aef892f0c
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 17#include <stdlib.h> 18#include <syslog.h> 19 20#include "private/libc_logging.h" 21 22static const char* syslog_log_tag = NULL; 23static int syslog_priority_mask = 0xff; 24 25void closelog() { 26 syslog_log_tag = NULL; 27} 28 29void openlog(const char* log_tag, int /*options*/, int /*facility*/) { 30 syslog_log_tag = log_tag; 31} 32 33int 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 42void 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 49void 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 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; 67 if (priority <= LOG_ERR) { 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); 78#endif 79} 80