115 lines
5.0 KiB
C
115 lines
5.0 KiB
C
/*
|
|
* logging.h - Centralised logging. Part of the Linux-NTFS project.
|
|
*
|
|
* Copyright (c) 2005 Richard Russon
|
|
*
|
|
* This program/include file is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as published
|
|
* by the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program/include file is distributed in the hope that it will be
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program (in the main directory of the Linux-NTFS
|
|
* distribution in the file COPYING); if not, write to the Free Software
|
|
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#ifndef _LOGGING_H_
|
|
#define _LOGGING_H_
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_STDARG_H
|
|
#include <stdarg.h>
|
|
#endif
|
|
|
|
#include "types.h"
|
|
|
|
struct ntfs_logging;
|
|
|
|
/* Function prototype for the logging handlers */
|
|
typedef int (logging_handler) (const char *handler, const char *file, int line,
|
|
int level, FILE *stream, const char *format, va_list args);
|
|
|
|
/**
|
|
* struct ntfs_logging - Control info for the logging system
|
|
* @levels: Bitfield of logging levels
|
|
* @flags: Flags to affect the output style
|
|
* @handler: Function to perform the actual logging
|
|
*/
|
|
struct ntfs_logging {
|
|
u32 levels;
|
|
u32 flags;
|
|
logging_handler *handler;
|
|
};
|
|
|
|
extern struct ntfs_logging ntfs_log;
|
|
|
|
void ntfs_logging_set_handler (logging_handler *handler);
|
|
|
|
/* Enable/disable certain log levels */
|
|
u32 ntfs_logging_set_levels (u32 levels);
|
|
u32 ntfs_logging_clear_levels (u32 levels);
|
|
u32 ntfs_logging_get_levels (void);
|
|
|
|
/* Enable/disable certain log flags */
|
|
u32 ntfs_logging_set_flags (u32 flags);
|
|
u32 ntfs_logging_clear_flags (u32 flags);
|
|
u32 ntfs_logging_get_flags (void);
|
|
|
|
BOOL ntfs_logging_parse_option (const char *option);
|
|
|
|
int ntfs_logging_redirect (const char *handler, const char *file, int line,
|
|
int level, FILE *stream, const char *format, ...)
|
|
__attribute__ ((format (printf, 6, 7)));
|
|
|
|
/* Logging handlers */
|
|
logging_handler ntfs_logging_handler_printf __attribute__ ((format (printf, 6, 0)));
|
|
logging_handler ntfs_logging_handler_colour __attribute__ ((format (printf, 6, 0)));
|
|
|
|
/* Logging levels - Determine what gets logged */
|
|
#define LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */
|
|
#define LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */
|
|
#define LOG_LEVEL_QUIET (1 << 2) /* Quietable output */
|
|
#define LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */
|
|
#define LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */
|
|
#define LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */
|
|
#define LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */
|
|
#define LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */
|
|
#define LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */
|
|
#define LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */
|
|
|
|
/* Logging style flags - Manage the style of the output */
|
|
#define LOG_FLAG_PREFIX (1 << 0) /* Prefix messages with "ERROR: ", etc */
|
|
#define LOG_FLAG_FILENAME (1 << 1) /* Show the file origin of the message */
|
|
#define LOG_FLAG_LINE (1 << 2) /* Show the line number of the message */
|
|
#define LOG_FLAG_FUNCTION (1 << 3) /* Show the function name containing the message */
|
|
|
|
/* Macros to simplify logging. One for each level defined above.
|
|
* Note, if DEBUG isn't defined, then log_debug has no effect.
|
|
*/
|
|
#define log_crit(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_CRITICAL,NULL,FORMAT,##ARGS)
|
|
#define log_error(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_ERROR,NULL,FORMAT,##ARGS)
|
|
#define log_info(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_INFO,NULL,FORMAT,##ARGS)
|
|
#define log_perror(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_PERROR,NULL,FORMAT,##ARGS)
|
|
#define log_progress(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_PROGRESS,NULL,FORMAT,##ARGS)
|
|
#define log_quiet(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_QUIET,NULL,FORMAT,##ARGS)
|
|
#define log_verbose(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_VERBOSE,NULL,FORMAT,##ARGS)
|
|
#define log_warn(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_WARNING,NULL,FORMAT,##ARGS)
|
|
|
|
#ifdef NTFS_DISABLE_DEBUG_LOGGING
|
|
#define log_debug(FORMAT, ARGS...)do {} while (0)
|
|
#define log_trace(FORMAT, ARGS...)do {} while (0)
|
|
#else
|
|
#define log_debug(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_DEBUG,NULL,FORMAT,##ARGS)
|
|
#define log_trace(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_TRACE,NULL,FORMAT,##ARGS)
|
|
#endif /* NTFS_DISABLE_DEBUG_LOGGING */
|
|
|
|
#endif /* _LOGGING_H_ */
|
|
|