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 ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 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
*
*/
2002-12-12 23:55:49 +03:00
# include <stdio.h> /* FILE */
# include <string.h> /* strerror() */
2001-10-04 14:13:07 +04:00
# include <errno.h>
2001-08-21 16:56:08 +04:00
2007-06-28 21:33:44 +04:00
# define _LOG_STDERR 128 / * force things to go to stderr, even if loglevel
would make them go to stdout */
2001-08-21 16:56:08 +04:00
# define _LOG_DEBUG 7
# define _LOG_INFO 6
# define _LOG_NOTICE 5
# define _LOG_WARN 4
# define _LOG_ERR 3
# define _LOG_FATAL 2
2004-03-26 14:45:01 +03:00
# define VERBOSE_BASE_LEVEL _LOG_WARN
2004-06-19 22:55:29 +04:00
# define SECURITY_LEVEL 0
2004-03-26 14:45:01 +03:00
2003-07-05 02:34:56 +04:00
void init_log_file ( const char * log_file , int append ) ;
void init_log_direct ( const char * log_file , int append ) ;
void init_log_while_suspended ( int log_while_suspended ) ;
2001-10-03 15:06:31 +04:00
void fin_log ( void ) ;
2003-07-05 02:34:56 +04:00
void release_log_memory ( void ) ;
2001-08-21 16:56:08 +04:00
void init_syslog ( int facility ) ;
void fin_syslog ( void ) ;
void init_verbose ( int level ) ;
void init_test ( int level ) ;
2002-01-29 20:23:33 +03:00
void init_partial ( int level ) ;
2004-11-19 22:25:07 +03:00
void init_md_filtering ( int level ) ;
2003-04-30 19:22:52 +04:00
void init_pvmove ( int level ) ;
2005-03-22 01:40:35 +03:00
void init_full_scan_done ( int level ) ;
2006-08-01 18:56:33 +04:00
void init_trust_cache ( int trustcache ) ;
2001-08-21 16:56:08 +04:00
void init_debug ( int level ) ;
2002-01-22 18:33:40 +03:00
void init_cmd_name ( int status ) ;
void init_msg_prefix ( const char * prefix ) ;
void init_indent ( int indent ) ;
2002-07-11 00:43:32 +04:00
void init_ignorelockingfailure ( int level ) ;
2005-03-22 01:55:12 +03:00
void init_lockingfailed ( int level ) ;
2004-06-19 22:55:29 +04:00
void init_security_level ( int level ) ;
2006-05-11 22:39:24 +04:00
void init_mirror_in_sync ( int in_sync ) ;
2007-01-20 01:21:45 +03:00
void init_dmeventd_monitor ( int reg ) ;
2007-01-26 00:22:30 +03:00
void init_ignore_suspended_devices ( int ignore ) ;
2002-01-22 18:33:40 +03:00
void set_cmd_name ( const char * cmd_name ) ;
2001-08-21 16:56:08 +04:00
int test_mode ( void ) ;
2002-01-29 20:23:33 +03:00
int partial_mode ( void ) ;
2004-11-19 22:25:07 +03:00
int md_filtering ( void ) ;
2003-04-30 19:22:52 +04:00
int pvmove_mode ( void ) ;
2005-03-22 01:40:35 +03:00
int full_scan_done ( void ) ;
2006-08-01 18:56:33 +04:00
int trust_cache ( void ) ;
2001-08-21 16:56:08 +04:00
int debug_level ( void ) ;
2002-07-11 00:43:32 +04:00
int ignorelockingfailure ( void ) ;
2005-03-22 01:55:12 +03:00
int lockingfailed ( void ) ;
2004-06-19 22:55:29 +04:00
int security_level ( void ) ;
2006-05-11 22:39:24 +04:00
int mirror_in_sync ( void ) ;
2007-01-26 00:22:30 +03:00
int ignore_suspended_devices ( void ) ;
2007-01-25 02:43:27 +03:00
# define DMEVENTD_MONITOR_IGNORE -1
2007-01-20 01:21:45 +03:00
int dmeventd_monitor_mode ( void ) ;
2001-08-21 16:56:08 +04:00
2006-04-13 21:32:24 +04:00
/* Suppress messages to stdout/stderr (1) or everywhere (2) */
/* Returns previous setting */
int log_suppress ( int suppress ) ;
2002-03-16 01:54:04 +03:00
2003-07-05 02:34:56 +04:00
/* Suppress messages to syslog */
void syslog_suppress ( int suppress ) ;
2004-03-26 17:47:14 +03:00
typedef void ( * lvm2_log_fn_t ) ( int level , const char * file , int line ,
const char * message ) ;
void init_log_fn ( lvm2_log_fn_t log_fn ) ;
2001-10-03 15:06:31 +04:00
void print_log ( int level , const char * file , int line , const char * format , . . . )
2002-12-12 23:55:49 +03:00
__attribute__ ( ( format ( printf , 4 , 5 ) ) ) ;
2001-08-21 16:56:08 +04:00
# define plog(l, x...) print_log(l, __FILE__, __LINE__ , ## x)
# define log_debug(x...) plog(_LOG_DEBUG, x)
# define log_info(x...) plog(_LOG_INFO, x)
# define log_notice(x...) plog(_LOG_NOTICE, x)
2007-06-28 21:33:44 +04:00
# define log_warn(x...) plog(_LOG_WARN | _LOG_STDERR, x)
2001-08-21 16:56:08 +04:00
# define log_err(x...) plog(_LOG_ERR, x)
# define log_fatal(x...) plog(_LOG_FATAL, x)
2002-02-11 21:25:18 +03:00
# define stack log_debug("<backtrace>") /* Backtrace on error */
2001-08-21 16:56:08 +04:00
2003-03-24 21:08:53 +03:00
# define log_error(args...) log_err(args)
2007-06-28 21:33:44 +04:00
# define log_print(args...) plog(_LOG_WARN, args)
2003-03-24 21:08:53 +03:00
# define log_verbose(args...) log_notice(args)
# define log_very_verbose(args...) log_info(args)
2001-08-21 16:56:08 +04:00
2001-10-23 22:20:27 +04:00
/* Two System call equivalents */
2001-10-10 20:36:32 +04:00
# define log_sys_error(x, y) \
log_err ( " %s: %s failed: %s " , y , x , strerror ( errno ) )
# 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)
# 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