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