18c2aff776a775d34a4c9893a4c72e0434d68e36artem/***************************************************************************
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CVSID: $Id$
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2006 Danny Kukawka, <danny.kukawka@web.de>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Licensed under the Academic Free License version 2.1
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is free software; you can redistribute it and/or modify
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * it under the terms of the GNU General Public License as published by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the Free Software Foundation; either version 2 of the License, or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (at your option) any later version.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is distributed in the hope that it will be useful,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * but WITHOUT ANY WARRANTY; without even the implied warranty of
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * GNU General Public License for more details.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You should have received a copy of the GNU General Public License
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * along with this program; if not, write to the Free Software
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18c2aff776a775d34a4c9893a4c72e0434d68e36artem **************************************************************************/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @defgroup HalDaemonLogging Logging system
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @ingroup HalDaemon
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @brief Logging system for the HAL daemon
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Disable all logging
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Enable all logging
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** enable usage of syslog for logging
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** disable usage of syslog for logging
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** allow setup logger from a addon/prober via the env
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Setup logging entry
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param priority Logging priority, one of HAL_LOGPRI_*
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param file Name of file where the log entry originated
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param line Line number of file
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param function Name of function
18c2aff776a775d34a4c9893a4c72e0434d68e36artemlogger_setup (int _priority, const char *_file, int _line, const char *_function)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Emit logging entry
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param format Message format string, printf style
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param ... Parameters for message, printf style
18c2aff776a775d34a4c9893a4c72e0434d68e36artem default: /* explicit fallthrough */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem snprintf (logmsg, sizeof(logmsg), "[%d]: %s.%03d %s %s:%d: %s\n", pid, tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem snprintf (logmsg, sizeof(logmsg), "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /** @todo Make programmatic interface to logging */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (priority != HAL_LOGPRI_TRACE && !syslog_enabled ) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem } else if (priority != HAL_LOGPRI_TRACE && syslog_enabled ) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* use syslog for debug/log messages if HAL started as daemon */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem default: /* explicit fallthrough */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem syslog (LOG_INFO, "%d: %s.%03d: %s", pid, tbuf, (int)(tnow.tv_usec/1000), buf);