/***************************************************************************
* CVSID: $Id$
*
* logger.c : Logging
*
* Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
* Copyright (C) 2006 Danny Kukawka, <danny.kukawka@web.de>
*
* Licensed under the Academic Free License version 2.1
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <syslog.h>
#include <unistd.h>
#include "logger.h"
/**
* @defgroup HalDaemonLogging Logging system
* @ingroup HalDaemon
* @brief Logging system for the HAL daemon
* @{
*/
static int priority;
static const char *file;
static int line;
static const char *function;
static int log_pid = 0;
static int syslog_enabled = 0;
/** Disable all logging
*
*/
void
logger_disable (void)
{
is_enabled = 0;
}
/** Enable all logging
*
*/
void
logger_enable (void)
{
is_enabled = 1;
}
/** enable usage of syslog for logging
*
*/
void
logger_enable_syslog (void)
{
syslog_enabled = 1;
}
/** disable usage of syslog for logging
*
*/
void
logger_disable_syslog (void)
{
syslog_enabled = 0;
}
*
*/
void
setup_logger (void)
{
is_enabled = 1;
log_pid = 1;
}
else
is_enabled = 0;
syslog_enabled = 1;
else
syslog_enabled = 0;
}
/** Setup logging entry
*
* @param priority Logging priority, one of HAL_LOGPRI_*
* @param file Name of file where the log entry originated
* @param line Line number of file
* @param function Name of function
*/
void
{
}
/** Emit logging entry
*
* @param format Message format string, printf style
* @param ... Parameters for message, printf style
*/
void
{
char *pri;
if (!is_enabled)
return;
switch (priority) {
case HAL_LOGPRI_TRACE:
pri = "[T]";
break;
case HAL_LOGPRI_DEBUG:
pri = "[D]";
break;
case HAL_LOGPRI_INFO:
pri = "[I]";
break;
case HAL_LOGPRI_WARNING:
pri = "[W]";
break;
default: /* explicit fallthrough */
case HAL_LOGPRI_ERROR:
pri = "[E]";
break;
}
if (log_pid) {
if ((int) pid == -1)
snprintf (logmsg, sizeof(logmsg), "[%d]: %s.%03d %s %s:%d: %s\n", pid, tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
} else {
snprintf (logmsg, sizeof(logmsg), "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
}
/** @todo Make programmatic interface to logging */
switch (priority) {
case HAL_LOGPRI_DEBUG:
case HAL_LOGPRI_INFO:
break;
case HAL_LOGPRI_WARNING:
break;
default: /* explicit fallthrough */
case HAL_LOGPRI_ERROR:
break;
}
}
}
void
{
if (!is_enabled)
return;
if ((int) pid == -1)
if (syslog_enabled)
else
}
/** @} */