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