Tizen 2.1 base
[external/device-mapper.git] / lib / log / log.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU Lesser General Public License v.2.1.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #ifndef _LVM_LOG_H
17 #define _LVM_LOG_H
18
19 /*
20  * printf()-style macros to use for messages:
21  *
22  *   log_error   - always print to stderr.
23  *   log_print   - always print to stdout.  Use this instead of printf.
24  *   log_verbose - print to stdout if verbose is set (-v)
25  *   log_very_verbose - print to stdout if verbose is set twice (-vv)
26  *   log_debug   - print to stdout if verbose is set three times (-vvv)
27  *
28  * In addition, messages will be logged to file or syslog if they
29  * are more serious than the log level specified with the log/debug_level
30  * parameter in the configuration file.  These messages get the file
31  * and line number prepended.  'stack' (without arguments) can be used 
32  * to log this information at debug level.
33  *
34  * log_sys_error and log_sys_very_verbose are for errors from system calls
35  * e.g. log_sys_error("stat", filename);
36  *      /dev/fd/7: stat failed: No such file or directory
37  *
38  */
39
40 #include <stdio.h>              /* FILE */
41 #include <string.h>             /* strerror() */
42 #include <errno.h>
43
44 #define EUNCLASSIFIED -1        /* Generic error code */
45
46 #define _LOG_STDERR 128 /* force things to go to stderr, even if loglevel
47                            would make them go to stdout */
48 #define _LOG_ONCE 256 /* downgrade to NOTICE if this has been already logged */
49 #define _LOG_DEBUG 7
50 #define _LOG_INFO 6
51 #define _LOG_NOTICE 5
52 #define _LOG_WARN 4
53 #define _LOG_ERR 3
54 #define _LOG_FATAL 2
55 #define INTERNAL_ERROR "Internal error: "
56
57 #define log_debug(x...) LOG_LINE(_LOG_DEBUG, x)
58 #define log_info(x...) LOG_LINE(_LOG_INFO, x)
59 #define log_notice(x...) LOG_LINE(_LOG_NOTICE, x)
60 #define log_warn(x...) LOG_LINE(_LOG_WARN | _LOG_STDERR, x)
61 #define log_warn_suppress(s, x...) LOG_LINE(s ? _LOG_NOTICE : _LOG_WARN | _LOG_STDERR, x)
62 #define log_err(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR, EUNCLASSIFIED, x)
63 #define log_err_suppress(s, x...) LOG_LINE_WITH_ERRNO(s ? _LOG_NOTICE : _LOG_ERR, EUNCLASSIFIED, x)
64 #define log_err_once(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR | _LOG_ONCE, EUNCLASSIFIED, x)
65 #define log_fatal(x...) LOG_LINE_WITH_ERRNO(_LOG_FATAL, EUNCLASSIFIED, x)
66
67 #define stack log_debug("<backtrace>")  /* Backtrace on error */
68 #define log_very_verbose(args...) log_info(args)
69 #define log_verbose(args...) log_notice(args)
70 #define log_print(args...) LOG_LINE(_LOG_WARN, args)
71 #define log_error(args...) log_err(args)
72 #define log_error_suppress(s, args...) log_err_suppress(s, args)
73 #define log_error_once(args...) log_err_once(args)
74 #define log_errno(args...) LOG_LINE_WITH_ERRNO(_LOG_ERR, args)
75
76 /* System call equivalents */
77 #define log_sys_error(x, y) \
78                 log_err("%s: %s failed: %s", y, x, strerror(errno))
79 #define log_sys_very_verbose(x, y) \
80                 log_info("%s: %s failed: %s", y, x, strerror(errno))
81 #define log_sys_debug(x, y) \
82                 log_debug("%s: %s failed: %s", y, x, strerror(errno))
83
84 #define return_0        do { stack; return 0; } while (0)
85 #define return_NULL     do { stack; return NULL; } while (0)
86 #define goto_out        do { stack; goto out; } while (0)
87 #define goto_bad        do { stack; goto bad; } while (0)
88
89 #endif