2001-08-21 16:56:08 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
2001-08-21 16:56:08 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-08-21 16:56:08 +04:00
*/
2001-09-25 16:49:28 +04:00
# ifndef _LVM_LOG_H
# define _LVM_LOG_H
2001-08-21 16:56:08 +04:00
2001-10-23 22:20:27 +04:00
/*
* printf ( ) - style macros to use for messages :
*
* log_error - always print to stderr .
* log_print - always print to stdout . Use this instead of printf .
* log_verbose - print to stdout if verbose is set ( - v )
* log_very_verbose - print to stdout if verbose is set twice ( - vv )
* log_debug - print to stdout if verbose is set three times ( - vvv )
*
* In addition , messages will be logged to file or syslog if they
* are more serious than the log level specified with the log / debug_level
* parameter in the configuration file . These messages get the file
* and line number prepended . ' stack ' ( without arguments ) can be used
* to log this information at debug level .
*
* log_sys_error and log_sys_very_verbose are for errors from system calls
* e . g . log_sys_error ( " stat " , filename ) ;
* / dev / fd / 7 : stat failed : No such file or directory
*
*/
2001-10-04 14:13:07 +04:00
# include <errno.h>
2001-08-21 16:56:08 +04:00
2009-07-16 17:13:33 +04:00
# define EUNCLASSIFIED -1 /* Generic error code */
2016-06-20 15:22:31 +03:00
# define _LOG_FATAL 0x0002
# define _LOG_ERR 0x0003
# define _LOG_WARN 0x0004
# define _LOG_NOTICE 0x0005
# define _LOG_INFO 0x0006
# define _LOG_DEBUG 0x0007
# define _LOG_STDERR 0x0080 /* force things to go to stderr, even if loglevel would make them go to stdout */
# define _LOG_ONCE 0x0100 /* downgrade to NOTICE if this has been already logged */
# define _LOG_BYPASS_REPORT 0x0200 /* do not log through report even if report available */
2016-11-02 16:39:13 +03:00
# define log_level(x) ((x) & 0x0f) /* obtain message level */
# define log_stderr(x) ((x) & _LOG_STDERR) /* obtain stderr bit */
# define log_once(x) ((x) & _LOG_ONCE) /* obtain once bit */
# define log_bypass_report(x) ((x) & _LOG_BYPASS_REPORT) /* obtain bypass bit */
2016-06-20 15:22:31 +03:00
2009-12-16 22:22:11 +03:00
# define INTERNAL_ERROR "Internal error: "
2001-08-21 16:56:08 +04:00
2013-01-08 02:25:19 +04:00
/*
* Classes available for debug log messages .
* These are also listed in doc / example . conf
* and lib / commands / toolcontext . c : _parse_debug_classes ( )
*/
# define LOG_CLASS_MEM 0x0001 /* "memory" */
# define LOG_CLASS_DEVS 0x0002 /* "devices" */
# define LOG_CLASS_ACTIVATION 0x0004 /* "activation" */
# define LOG_CLASS_ALLOC 0x0008 /* "allocation" */
# define LOG_CLASS_LVMETAD 0x0010 /* "lvmetad" */
# define LOG_CLASS_METADATA 0x0020 /* "metadata" */
# define LOG_CLASS_CACHE 0x0040 /* "cache" */
# define LOG_CLASS_LOCKING 0x0080 /* "locking" */
2015-05-12 16:26:26 +03:00
# define LOG_CLASS_LVMPOLLD 0x0100 /* "lvmpolld" */
2016-02-22 18:42:03 +03:00
# define LOG_CLASS_DBUS 0x0200 /* "dbus" */
2013-01-08 02:25:19 +04:00
2009-07-10 13:59:37 +04:00
# define log_debug(x...) LOG_LINE(_LOG_DEBUG, x)
2013-01-08 02:25:19 +04:00
# define log_debug_mem(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_MEM, x)
# define log_debug_devs(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_DEVS, x)
# define log_debug_activation(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_ACTIVATION, x)
# define log_debug_alloc(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_ALLOC, x)
# define log_debug_lvmetad(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_LVMETAD, x)
# define log_debug_metadata(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_METADATA, x)
# define log_debug_cache(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_CACHE, x)
# define log_debug_locking(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_LOCKING, x)
2015-05-12 16:26:26 +03:00
# define log_debug_lvmpolld(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_LVMPOLLD, x)
2016-02-22 18:42:03 +03:00
# define log_debug_dbus(x...) LOG_LINE_WITH_CLASS(_LOG_DEBUG, LOG_CLASS_DBUS, x)
2013-01-08 02:25:19 +04:00
2009-07-10 13:59:37 +04:00
# define log_info(x...) LOG_LINE(_LOG_INFO, x)
# define log_notice(x...) LOG_LINE(_LOG_NOTICE, x)
# define log_warn(x...) LOG_LINE(_LOG_WARN | _LOG_STDERR, x)
2010-02-15 19:46:56 +03:00
# define log_warn_suppress(s, x...) LOG_LINE(s ? _LOG_NOTICE : _LOG_WARN | _LOG_STDERR, x)
2009-07-16 17:13:33 +04:00
# define log_err(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR, EUNCLASSIFIED, x)
2010-02-15 19:46:56 +03:00
# define log_err_suppress(s, x...) LOG_LINE_WITH_ERRNO(s ? _LOG_NOTICE : _LOG_ERR, EUNCLASSIFIED, x)
2010-05-06 02:37:52 +04:00
# define log_err_once(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR | _LOG_ONCE, EUNCLASSIFIED, x)
2009-07-16 17:13:33 +04:00
# define log_fatal(x...) LOG_LINE_WITH_ERRNO(_LOG_FATAL, EUNCLASSIFIED, x)
2001-08-21 16:56:08 +04:00
2002-02-11 21:25:18 +03:00
# define stack log_debug("<backtrace>") /* Backtrace on error */
2003-03-24 21:08:53 +03:00
# define log_very_verbose(args...) log_info(args)
2008-10-30 20:27:28 +03:00
# define log_verbose(args...) log_notice(args)
2009-07-10 13:59:37 +04:00
# define log_print(args...) LOG_LINE(_LOG_WARN, args)
config: add silent mode
Accept -q as the short form of --quiet.
Suppress non-essential standard output if -q is given twice.
Treat log/silent in lvm.conf as equivalent to -qq.
Review all log_print messages and change some to
log_print_unless_silent.
When silent, the following commands still produce output:
dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
pvs, version, vgcfgrestore -l, vgdisplay, vgs.
[Needs checking.]
Non-essential messages are shifted from log level 4 to log level 5
for syslog and lvm2_log_fn purposes.
2012-08-25 23:35:48 +04:00
# define log_print_unless_silent(args...) LOG_LINE(silent_mode() ? _LOG_NOTICE : _LOG_WARN, args)
2008-10-30 20:27:28 +03:00
# define log_error(args...) log_err(args)
2010-02-15 19:46:56 +03:00
# define log_error_suppress(s, args...) log_err_suppress(s, args)
2010-05-06 02:37:52 +04:00
# define log_error_once(args...) log_err_once(args)
2009-07-16 04:52:06 +04:00
# define log_errno(args...) LOG_LINE_WITH_ERRNO(_LOG_ERR, args)
2001-08-21 16:56:08 +04:00
2008-10-30 20:27:28 +03:00
/* System call equivalents */
2001-10-10 20:36:32 +04:00
# define log_sys_error(x, y) \
2013-08-12 21:40:41 +04:00
log_err ( " %s%s%s failed: %s " , y , * y ? " : " : " " , x , strerror ( errno ) )
2011-08-09 15:44:57 +04:00
# define log_sys_error_suppress(s, x, y) \
2013-08-12 21:40:41 +04:00
log_err_suppress ( s , " %s%s%s failed: %s " , y , * y ? " : " : " " , x , strerror ( errno ) )
2001-10-10 20:36:32 +04:00
# define log_sys_very_verbose(x, y) \
log_info ( " %s: %s failed: %s " , y , x , strerror ( errno ) )
2003-07-05 02:34:56 +04:00
# define log_sys_debug(x, y) \
log_debug ( " %s: %s failed: %s " , y , x , strerror ( errno ) )
2001-10-10 20:36:32 +04:00
2005-11-09 01:52:26 +03:00
# define return_0 do { stack; return 0; } while (0)
# define return_NULL do { stack; return NULL; } while (0)
2015-02-13 17:58:51 +03:00
# define return_EINVALID_CMD_LINE \
do { stack ; return EINVALID_CMD_LINE ; } while ( 0 )
2013-07-01 13:27:22 +04:00
# define return_ECMD_FAILED do { stack; return ECMD_FAILED; } while (0)
2005-11-09 01:52:26 +03:00
# define goto_out do { stack; goto out; } while (0)
2007-04-26 20:44:59 +04:00
# define goto_bad do { stack; goto bad; } while (0)
2005-11-09 01:52:26 +03:00
2001-08-21 16:56:08 +04:00
# endif