]>
Commit | Line | Data |
---|---|---|
df88dece | 1 | /* |
6606c3ae | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
be684599 | 3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. |
df88dece | 4 | * |
6606c3ae AK |
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 | |
be684599 | 9 | * of the GNU Lesser General Public License v.2.1. |
6606c3ae | 10 | * |
be684599 | 11 | * You should have received a copy of the GNU Lesser General Public License |
6606c3ae AK |
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 | |
df88dece JT |
14 | */ |
15 | ||
269930c0 AK |
16 | #ifndef _LVM_LOG_H |
17 | #define _LVM_LOG_H | |
df88dece | 18 | |
4790fce2 AK |
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) | |
4790fce2 AK |
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 | ||
4c64ed4c AK |
40 | #include <stdio.h> /* FILE */ |
41 | #include <string.h> /* strerror() */ | |
e6efb2b0 | 42 | #include <errno.h> |
df88dece | 43 | |
c791c54e AK |
44 | #define EUNCLASSIFIED -1 /* Generic error code */ |
45 | ||
e7ddf416 PR |
46 | #define _LOG_STDERR 128 /* force things to go to stderr, even if loglevel |
47 | would make them go to stdout */ | |
9409998d | 48 | #define _LOG_ONCE 256 /* downgrade to NOTICE if this has been already logged */ |
df88dece JT |
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 | |
550cae23 | 55 | #define INTERNAL_ERROR "Internal error: " |
df88dece | 56 | |
a9cb6969 AK |
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) | |
b9259173 | 61 | #define log_warn_suppress(s, x...) LOG_LINE(s ? _LOG_NOTICE : _LOG_WARN | _LOG_STDERR, x) |
c791c54e | 62 | #define log_err(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR, EUNCLASSIFIED, x) |
b9259173 | 63 | #define log_err_suppress(s, x...) LOG_LINE_WITH_ERRNO(s ? _LOG_NOTICE : _LOG_ERR, EUNCLASSIFIED, x) |
9409998d | 64 | #define log_err_once(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR | _LOG_ONCE, EUNCLASSIFIED, x) |
c791c54e | 65 | #define log_fatal(x...) LOG_LINE_WITH_ERRNO(_LOG_FATAL, EUNCLASSIFIED, x) |
df88dece | 66 | |
8d6a8717 | 67 | #define stack log_debug("<backtrace>") /* Backtrace on error */ |
26e7f2e0 | 68 | #define log_very_verbose(args...) log_info(args) |
84b9ec97 | 69 | #define log_verbose(args...) log_notice(args) |
a9cb6969 | 70 | #define log_print(args...) LOG_LINE(_LOG_WARN, args) |
84b9ec97 | 71 | #define log_error(args...) log_err(args) |
b9259173 | 72 | #define log_error_suppress(s, args...) log_err_suppress(s, args) |
9409998d | 73 | #define log_error_once(args...) log_err_once(args) |
9fac4435 | 74 | #define log_errno(args...) LOG_LINE_WITH_ERRNO(_LOG_ERR, args) |
df88dece | 75 | |
84b9ec97 | 76 | /* System call equivalents */ |
2d9133bb AK |
77 | #define log_sys_error(x, y) \ |
78 | log_err("%s: %s failed: %s", y, x, strerror(errno)) | |
cf992769 PR |
79 | #define log_sys_error_suppress(s, x, y) \ |
80 | log_err_suppress(s, "%s: %s failed: %s", y, x, strerror(errno)) | |
2d9133bb AK |
81 | #define log_sys_very_verbose(x, y) \ |
82 | log_info("%s: %s failed: %s", y, x, strerror(errno)) | |
914c9723 AK |
83 | #define log_sys_debug(x, y) \ |
84 | log_debug("%s: %s failed: %s", y, x, strerror(errno)) | |
2d9133bb | 85 | |
5f4b2acf AK |
86 | #define return_0 do { stack; return 0; } while (0) |
87 | #define return_NULL do { stack; return NULL; } while (0) | |
88 | #define goto_out do { stack; goto out; } while (0) | |
4f2f566b | 89 | #define goto_bad do { stack; goto bad; } while (0) |
5f4b2acf | 90 | |
df88dece | 91 | #endif |