1 /* $NetBSD: log.h,v 1.1.1.1 2008/12/22 00:17:52 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 6 * 7 * This file is part of LVM2. 8 * 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. 12 * 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 16 */ 17 18 #ifndef _LVM_LOG_H 19 #define _LVM_LOG_H 20 21 /* 22 * printf()-style macros to use for messages: 23 * 24 * log_error - always print to stderr. 25 * log_print - always print to stdout. Use this instead of printf. 26 * log_verbose - print to stdout if verbose is set (-v) 27 * log_very_verbose - print to stdout if verbose is set twice (-vv) 28 * log_debug - print to stdout if verbose is set three times (-vvv) 29 * 30 * In addition, messages will be logged to file or syslog if they 31 * are more serious than the log level specified with the log/debug_level 32 * parameter in the configuration file. These messages get the file 33 * and line number prepended. 'stack' (without arguments) can be used 34 * to log this information at debug level. 35 * 36 * log_sys_error and log_sys_very_verbose are for errors from system calls 37 * e.g. log_sys_error("stat", filename); 38 * /dev/fd/7: stat failed: No such file or directory 39 * 40 */ 41 42 #include <stdio.h> /* FILE */ 43 #include <string.h> /* strerror() */ 44 #include <errno.h> 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_DEBUG 7 49 #define _LOG_INFO 6 50 #define _LOG_NOTICE 5 51 #define _LOG_WARN 4 52 #define _LOG_ERR 3 53 #define _LOG_FATAL 2 54 55 #define log_debug(x...) plog(_LOG_DEBUG, x) 56 #define log_info(x...) plog(_LOG_INFO, x) 57 #define log_notice(x...) plog(_LOG_NOTICE, x) 58 #define log_warn(x...) plog(_LOG_WARN | _LOG_STDERR, x) 59 #define log_err(x...) plog(_LOG_ERR, x) 60 #define log_fatal(x...) plog(_LOG_FATAL, x) 61 62 #define stack log_debug("<backtrace>") /* Backtrace on error */ 63 #define log_very_verbose(args...) log_info(args) 64 #define log_verbose(args...) log_notice(args) 65 #define log_print(args...) plog(_LOG_WARN, args) 66 #define log_error(args...) log_err(args) 67 68 /* System call equivalents */ 69 #define log_sys_error(x, y) \ 70 log_err("%s: %s failed: %s", y, x, strerror(errno)) 71 #define log_sys_very_verbose(x, y) \ 72 log_info("%s: %s failed: %s", y, x, strerror(errno)) 73 #define log_sys_debug(x, y) \ 74 log_debug("%s: %s failed: %s", y, x, strerror(errno)) 75 76 #define return_0 do { stack; return 0; } while (0) 77 #define return_NULL do { stack; return NULL; } while (0) 78 #define goto_out do { stack; goto out; } while (0) 79 #define goto_bad do { stack; goto bad; } while (0) 80 81 #endif 82