]>
sourceware.org Git - lvm2.git/blob - lib/log/log.h
9ce630cc76ba5f2be4118052be02cef51ff6f7c9
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * printf()-style macros to use for messages:
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)
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.
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
42 #define EUNCLASSIFIED -1 /* Generic error code */
44 #define _LOG_FATAL 0x0002
45 #define _LOG_ERR 0x0003
46 #define _LOG_WARN 0x0004
47 #define _LOG_NOTICE 0x0005
48 #define _LOG_INFO 0x0006
49 #define _LOG_DEBUG 0x0007
50 #define _LOG_STDERR 0x0080 /* force things to go to stderr, even if loglevel would make them go to stdout */
51 #define _LOG_ONCE 0x0100 /* downgrade to NOTICE if this has been already logged */
52 #define _LOG_BYPASS_REPORT 0x0200 /* do not log through report even if report available */
53 #define log_level(x) ((x) & 0x0f) /* obtain message level */
54 #define log_stderr(x) ((x) & _LOG_STDERR) /* obtain stderr bit */
55 #define log_once(x) ((x) & _LOG_ONCE) /* obtain once bit */
56 #define log_bypass_report(x) ((x) & _LOG_BYPASS_REPORT)/* obtain bypass bit */
58 #define INTERNAL_ERROR "Internal error: "
60 #define LOG_DEBUG_FIELD_ALL 0x0000
61 #define LOG_DEBUG_FIELD_TIME 0x0001
62 #define LOG_DEBUG_FIELD_COMMAND 0x0002
63 #define LOG_DEBUG_FIELD_FILELINE 0x0004
64 #define LOG_DEBUG_FIELD_MESSAGE 0x0008
66 #define LOG_JOURNAL_COMMAND 0x0001
67 #define LOG_JOURNAL_OUTPUT 0x0002
68 #define LOG_JOURNAL_DEBUG 0x0004
72 * Classes available for debug log messages.
73 * These are also listed in doc/example.conf
74 * and lib/commands/toolcontext.c:_parse_debug_classes()
76 #define LOG_CLASS_MEM 0x0001 /* "memory" */
77 #define LOG_CLASS_DEVS 0x0002 /* "devices" */
78 #define LOG_CLASS_ACTIVATION 0x0004 /* "activation" */
79 #define LOG_CLASS_ALLOC 0x0008 /* "allocation" */
80 #define LOG_CLASS_LVMETAD 0x0010 /* "lvmetad" */
81 #define LOG_CLASS_METADATA 0x0020 /* "metadata" */
82 #define LOG_CLASS_CACHE 0x0040 /* "cache" */
83 #define LOG_CLASS_LOCKING 0x0080 /* "locking" */
84 #define LOG_CLASS_LVMPOLLD 0x0100 /* "lvmpolld" */
85 #define LOG_CLASS_DBUS 0x0200 /* "dbus" */
86 #define LOG_CLASS_IO 0x0400 /* "io" */
88 #define log_debug(x...) LOG_LINE(_LOG_DEBUG, x)
89 #define log_debug_mem(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_MEM, x)
90 #define log_debug_devs(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_DEVS, x)
91 #define log_debug_activation(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_ACTIVATION, x)
92 #define log_debug_alloc(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_ALLOC, x)
93 #define log_debug_metadata(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_METADATA, x)
94 #define log_debug_cache(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_CACHE, x)
95 #define log_debug_locking(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_LOCKING, x)
96 #define log_debug_lvmpolld(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_LVMPOLLD, x)
97 #define log_debug_dbus(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_DBUS, x)
98 #define log_debug_io(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_IO, x)
100 #define log_info(x...) LOG_LINE(_LOG_INFO, x)
101 #define log_notice(x...) LOG_LINE(_LOG_NOTICE, x)
102 #define log_warn(x...) LOG_LINE(_LOG_WARN | _LOG_STDERR, x)
103 #define log_warn_suppress(s, x...) LOG_LINE(s ? _LOG_NOTICE : _LOG_WARN | _LOG_STDERR, x)
104 #define log_err(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR, EUNCLASSIFIED, x)
105 #define log_err_suppress(s, x...) LOG_LINE_WITH_ERRNO(s ? _LOG_NOTICE : _LOG_ERR, EUNCLASSIFIED, x)
106 #define log_err_once(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR | _LOG_ONCE, EUNCLASSIFIED, x)
107 #define log_fatal(x...) LOG_LINE_WITH_ERRNO(_LOG_FATAL, EUNCLASSIFIED, x)
109 #define stack log_debug("<backtrace>") /* Backtrace on error */
110 #define log_very_verbose(args...) log_info(args)
111 #define log_verbose(args...) log_notice(args)
112 #define log_print(args...) LOG_LINE(_LOG_WARN, args)
113 #define log_print_unless_silent(args...) LOG_LINE(silent_mode() ? _LOG_NOTICE : _LOG_WARN, args)
114 #define log_error(args...) log_err(args)
115 #define log_error_suppress(s, args...) log_err_suppress(s, args)
116 #define log_error_once(args...) log_err_once(args)
117 #define log_errno(args...) LOG_LINE_WITH_ERRNO(_LOG_ERR, args)
119 /* System call equivalents */
120 #define log_sys_error(x, y) \
121 log_err("%s%s%s failed: %s", y, *y ? ": " : "", x, strerror(errno))
122 #define log_sys_error_suppress(s, x, y) \
123 log_err_suppress(s, "%s%s%s failed: %s", y, *y ? ": " : "", x, strerror(errno))
124 #define log_sys_very_verbose(x, y) \
125 log_info("%s: %s failed: %s", y, x, strerror(errno))
126 #define log_sys_debug(x, y) \
127 log_debug("%s: %s failed: %s", y, x, strerror(errno))
129 #define return_0 do { stack; return 0; } while (0)
130 #define return_NULL do { stack; return NULL; } while (0)
131 #define return_false do { stack; return false; } while (0)
132 #define return_EINVALID_CMD_LINE \
133 do { stack; return EINVALID_CMD_LINE; } while (0)
134 #define return_ECMD_FAILED do { stack; return ECMD_FAILED; } while (0)
135 #define goto_out do { stack; goto out; } while (0)
136 #define goto_bad do { stack; goto bad; } while (0)
This page took 0.051305 seconds and 6 git commands to generate.