xref: /titanic_41/usr/src/cmd/hal/hald/logger.h (revision 3893cb7fe5bfa1c9a4f7954517a917367f6cf081)
1 /***************************************************************************
2  * CVSID: $Id$
3  *
4  * logger.h : Logging facility
5  *
6  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
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.
14  *
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.
19  *
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
23  *
24  **************************************************************************/
25 
26 #ifndef LOGGER_H
27 #define LOGGER_H
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 
32 /**
33  * @addtogroup HalDaemonLogging
34  *
35  * @{
36  */
37 
38 
39 /** Logging levels for HAL daemon
40  */
41 enum {
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 */
47 };
48 
49 void logger_setup (int priority, const char *file, int line, const char *function);
50 
51 void logger_emit (const char *format, ...);
52 void logger_forward_debug (const char *format, ...);
53 
54 void logger_enable (void);
55 void logger_disable (void);
56 
57 void logger_enable_syslog (void);
58 void logger_disable_syslog (void);
59 
60 void setup_logger (void);
61 
62 #ifdef __SUNPRO_C
63 #define __FUNCTION__ __func__
64 #endif
65 
66 /** Trace logging macro */
67 #define HAL_TRACE(expr)   do {logger_setup(HAL_LOGPRI_TRACE,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
68 
69 /** Debug information logging macro */
70 #define HAL_DEBUG(expr)   do {logger_setup(HAL_LOGPRI_DEBUG,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
71 
72 /** Information level logging macro */
73 #define HAL_INFO(expr)    do {logger_setup(HAL_LOGPRI_INFO,    __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
74 
75 /** Warning level logging macro */
76 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
77 
78 /** Error leve logging macro */
79 #define HAL_ERROR(expr)   do {logger_setup(HAL_LOGPRI_ERROR,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
80 
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)
83 
84 /** @} */
85 
86 #endif				/* LOGGER_H */
87