1 /***************************************************************************
4 * logger.h : Logging facility
6 * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
8 * Licensed under the Academic Free License version 2.1
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 **************************************************************************/
33 * @addtogroup HalDaemonLogging
39 /** Logging levels for HAL daemon
42 HAL_LOGPRI_TRACE
= (1 << 0), /**< function call sequences */
43 HAL_LOGPRI_DEBUG
= (1 << 1), /**< debug statements in code */
44 HAL_LOGPRI_INFO
= (1 << 2), /**< informational level */
45 HAL_LOGPRI_WARNING
= (1 << 3), /**< warnings */
46 HAL_LOGPRI_ERROR
= (1 << 4) /**< error */
49 void logger_setup (int priority
, const char *file
, int line
, const char *function
);
51 void logger_emit (const char *format
, ...);
52 void logger_forward_debug (const char *format
, ...);
54 void logger_enable (void);
55 void logger_disable (void);
57 void logger_enable_syslog (void);
58 void logger_disable_syslog (void);
60 void setup_logger (void);
63 #define __FUNCTION__ __func__
66 /** Trace logging macro */
67 #define HAL_TRACE(expr) do {logger_setup(HAL_LOGPRI_TRACE, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
69 /** Debug information logging macro */
70 #define HAL_DEBUG(expr) do {logger_setup(HAL_LOGPRI_DEBUG, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
72 /** Information level logging macro */
73 #define HAL_INFO(expr) do {logger_setup(HAL_LOGPRI_INFO, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
75 /** Warning level logging macro */
76 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
78 /** Error leve logging macro */
79 #define HAL_ERROR(expr) do {logger_setup(HAL_LOGPRI_ERROR, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
81 /** Macro for terminating the program on an unrecoverable error */
82 #define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)