1 /* 2 * 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel (at) holtmann.org> 6 * 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 */ 23 24 #ifdef HAVE_CONFIG_H 25 #include <config.h> 26 #endif 27 28 #include <stdio.h> 29 #include <stdarg.h> 30 #include <syslog.h> 31 32 #include <glib.h> 33 34 #include "log.h" 35 36 void info(const char *format, ...) 37 { 38 va_list ap; 39 40 va_start(ap, format); 41 42 vsyslog(LOG_INFO, format, ap); 43 44 va_end(ap); 45 } 46 47 void error(const char *format, ...) 48 { 49 va_list ap; 50 51 va_start(ap, format); 52 53 vsyslog(LOG_ERR, format, ap); 54 55 va_end(ap); 56 } 57 58 void btd_debug(const char *format, ...) 59 { 60 va_list ap; 61 62 va_start(ap, format); 63 64 vsyslog(LOG_DEBUG, format, ap); 65 66 va_end(ap); 67 } 68 69 extern struct btd_debug_desc __start___debug[]; 70 extern struct btd_debug_desc __stop___debug[]; 71 72 static gchar **enabled = NULL; 73 74 static gboolean is_enabled(struct btd_debug_desc *desc) 75 { 76 int i; 77 78 if (enabled == NULL) 79 return 0; 80 81 for (i = 0; enabled[i] != NULL; i++) 82 if (desc->file != NULL && g_pattern_match_simple(enabled[i], 83 desc->file) == TRUE) 84 return 1; 85 86 return 0; 87 } 88 89 void __btd_toggle_debug(void) 90 { 91 struct btd_debug_desc *desc; 92 93 for (desc = __start___debug; desc < __stop___debug; desc++) 94 desc->flags |= BTD_DEBUG_FLAG_PRINT; 95 } 96 97 void __btd_log_init(const char *debug, int detach) 98 { 99 int option = LOG_NDELAY | LOG_PID; 100 struct btd_debug_desc *desc; 101 102 if (debug != NULL) 103 enabled = g_strsplit_set(debug, ":, ", 0); 104 105 for (desc = __start___debug; desc < __stop___debug; desc++) 106 if (is_enabled(desc)) 107 desc->flags |= BTD_DEBUG_FLAG_PRINT; 108 109 if (!detach) 110 option |= LOG_PERROR; 111 112 openlog("bluetoothd", option, LOG_DAEMON); 113 114 syslog(LOG_INFO, "Bluetooth deamon %s", VERSION); 115 } 116 117 void __btd_log_cleanup(void) 118 { 119 closelog(); 120 121 g_strfreev(enabled); 122 } 123