xref: /onnv-gate/usr/src/cmd/hal/hald/logger.h (revision 2912:85ea316d9c18)
1*2912Sartem /***************************************************************************
2*2912Sartem  * CVSID: $Id$
3*2912Sartem  *
4*2912Sartem  * logger.h : Logging facility
5*2912Sartem  *
6*2912Sartem  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
7*2912Sartem  *
8*2912Sartem  * Licensed under the Academic Free License version 2.1
9*2912Sartem  *
10*2912Sartem  * This program is free software; you can redistribute it and/or modify
11*2912Sartem  * it under the terms of the GNU General Public License as published by
12*2912Sartem  * the Free Software Foundation; either version 2 of the License, or
13*2912Sartem  * (at your option) any later version.
14*2912Sartem  *
15*2912Sartem  * This program is distributed in the hope that it will be useful,
16*2912Sartem  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*2912Sartem  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*2912Sartem  * GNU General Public License for more details.
19*2912Sartem  *
20*2912Sartem  * You should have received a copy of the GNU General Public License
21*2912Sartem  * along with this program; if not, write to the Free Software
22*2912Sartem  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23*2912Sartem  *
24*2912Sartem  **************************************************************************/
25*2912Sartem 
26*2912Sartem #ifndef LOGGER_H
27*2912Sartem #define LOGGER_H
28*2912Sartem 
29*2912Sartem #include <stdio.h>
30*2912Sartem #include <stdlib.h>
31*2912Sartem 
32*2912Sartem /**
33*2912Sartem  * @addtogroup HalDaemonLogging
34*2912Sartem  *
35*2912Sartem  * @{
36*2912Sartem  */
37*2912Sartem 
38*2912Sartem 
39*2912Sartem /** Logging levels for HAL daemon
40*2912Sartem  */
41*2912Sartem enum {
42*2912Sartem 	HAL_LOGPRI_TRACE = (1 << 0),   /**< function call sequences */
43*2912Sartem 	HAL_LOGPRI_DEBUG = (1 << 1),   /**< debug statements in code */
44*2912Sartem 	HAL_LOGPRI_INFO = (1 << 2),    /**< informational level */
45*2912Sartem 	HAL_LOGPRI_WARNING = (1 << 3), /**< warnings */
46*2912Sartem 	HAL_LOGPRI_ERROR = (1 << 4)    /**< error */
47*2912Sartem };
48*2912Sartem 
49*2912Sartem void logger_setup (int priority, const char *file, int line, const char *function);
50*2912Sartem 
51*2912Sartem void logger_emit (const char *format, ...);
52*2912Sartem void logger_forward_debug (const char *format, ...);
53*2912Sartem 
54*2912Sartem void logger_enable (void);
55*2912Sartem void logger_disable (void);
56*2912Sartem 
57*2912Sartem void logger_enable_syslog (void);
58*2912Sartem void logger_disable_syslog (void);
59*2912Sartem 
60*2912Sartem void setup_logger (void);
61*2912Sartem 
62*2912Sartem #ifdef __SUNPRO_C
63*2912Sartem #define __FUNCTION__ __func__
64*2912Sartem #endif
65*2912Sartem 
66*2912Sartem /** Trace logging macro */
67*2912Sartem #define HAL_TRACE(expr)   do {logger_setup(HAL_LOGPRI_TRACE,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
68*2912Sartem 
69*2912Sartem /** Debug information logging macro */
70*2912Sartem #define HAL_DEBUG(expr)   do {logger_setup(HAL_LOGPRI_DEBUG,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
71*2912Sartem 
72*2912Sartem /** Information level logging macro */
73*2912Sartem #define HAL_INFO(expr)    do {logger_setup(HAL_LOGPRI_INFO,    __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
74*2912Sartem 
75*2912Sartem /** Warning level logging macro */
76*2912Sartem #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
77*2912Sartem 
78*2912Sartem /** Error leve logging macro */
79*2912Sartem #define HAL_ERROR(expr)   do {logger_setup(HAL_LOGPRI_ERROR,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
80*2912Sartem 
81*2912Sartem /** Macro for terminating the program on an unrecoverable error */
82*2912Sartem #define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)
83*2912Sartem 
84*2912Sartem /** @} */
85*2912Sartem 
86*2912Sartem #endif				/* LOGGER_H */
87