blob: d3b1b1eb782fddaa578c02b1ad1b1a7e028799da [file] [log] [blame]
Elliott Hughesb7661362014-07-21 16:35:24 -07001/*
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 Hughesb7661362014-07-21 16:35:24 -070017#include <stdlib.h>
Elliott Hughes4126c122014-07-23 11:38:38 -070018#include <syslog.h>
Elliott Hughesb7661362014-07-21 16:35:24 -070019
20#include "private/libc_logging.h"
21
22static const char* syslog_log_tag = NULL;
23static int syslog_priority_mask = 0xff;
24
25void closelog() {
Elliott Hughes4126c122014-07-23 11:38:38 -070026 syslog_log_tag = NULL;
Elliott Hughesb7661362014-07-21 16:35:24 -070027}
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
Christopher Ferrisbc74ecf2014-07-23 18:05:58 -070049void 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 Hughesb7661362014-07-21 16:35:24 -070053 // 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 Hughes4126c122014-07-23 11:38:38 -070067 if (priority <= LOG_ERR) {
Elliott Hughesb7661362014-07-21 16:35:24 -070068 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 Ferrisbc74ecf2014-07-23 18:05:58 -070078#endif
Elliott Hughesb7661362014-07-21 16:35:24 -070079}