1/* 2 * logging.h - Centralised logging. Originated from the Linux-NTFS project. 3 * 4 * Copyright (c) 2005 Richard Russon 5 * Copyright (c) 2007-2008 Szabolcs Szakacsits 6 * 7 * This program/include file is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as published 9 * by the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program/include file is distributed in the hope that it will be 13 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program (in the main directory of the NTFS-3G 19 * distribution in the file COPYING); if not, write to the Free Software 20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23#ifndef _LOGGING_H_ 24#define _LOGGING_H_ 25 26#ifdef HAVE_CONFIG_H 27#include "config.h" 28#endif 29 30#ifdef HAVE_STDARG_H 31#include <stdarg.h> 32#endif 33 34#include "types.h" 35 36//#define DEBUG 37 38/* Function prototype for the logging handlers */ 39typedef int (ntfs_log_handler)(const char *function, const char *file, int line, 40 u32 level, void *data, const char *format, va_list args); 41 42/* Set the logging handler from one of the functions, below. */ 43void ntfs_log_set_handler(ntfs_log_handler *handler 44 __attribute__((format(printf, 6, 0)))); 45 46/* Logging handlers */ 47ntfs_log_handler ntfs_log_handler_syslog __attribute__((format(printf, 6, 0))); 48ntfs_log_handler ntfs_log_handler_fprintf __attribute__((format(printf, 6, 0))); 49ntfs_log_handler ntfs_log_handler_null __attribute__((format(printf, 6, 0))); 50ntfs_log_handler ntfs_log_handler_stdout __attribute__((format(printf, 6, 0))); 51ntfs_log_handler ntfs_log_handler_outerr __attribute__((format(printf, 6, 0))); 52ntfs_log_handler ntfs_log_handler_stderr __attribute__((format(printf, 6, 0))); 53 54/* Enable/disable certain log levels */ 55u32 ntfs_log_set_levels(u32 levels); 56u32 ntfs_log_clear_levels(u32 levels); 57u32 ntfs_log_get_levels(void); 58 59/* Enable/disable certain log flags */ 60u32 ntfs_log_set_flags(u32 flags); 61u32 ntfs_log_clear_flags(u32 flags); 62u32 ntfs_log_get_flags(void); 63 64/* Turn command-line options into logging flags */ 65BOOL ntfs_log_parse_option(const char *option); 66 67int ntfs_log_redirect(const char *function, const char *file, int line, 68 u32 level, void *data, const char *format, ...) 69 __attribute__((format(printf, 6, 7))); 70 71/* Logging levels - Determine what gets logged */ 72#define NTFS_LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ 73#define NTFS_LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ 74#define NTFS_LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ 75#define NTFS_LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */ 76#define NTFS_LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */ 77#define NTFS_LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */ 78#define NTFS_LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */ 79#define NTFS_LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */ 80#define NTFS_LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */ 81#define NTFS_LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */ 82#define NTFS_LOG_LEVEL_ENTER (1 << 10) /* Enter a function */ 83#define NTFS_LOG_LEVEL_LEAVE (1 << 11) /* Leave a function */ 84 85/* Logging style flags - Manage the style of the output */ 86#define NTFS_LOG_FLAG_PREFIX (1 << 0) /* Prefix messages with "ERROR: ", etc */ 87#define NTFS_LOG_FLAG_FILENAME (1 << 1) /* Show the file origin of the message */ 88#define NTFS_LOG_FLAG_LINE (1 << 2) /* Show the line number of the message */ 89#define NTFS_LOG_FLAG_FUNCTION (1 << 3) /* Show the function name containing the message */ 90#define NTFS_LOG_FLAG_ONLYNAME (1 << 4) /* Only display the filename, not the pathname */ 91 92/* Macros to simplify logging. One for each level defined above. 93 * Note, ntfs_log_debug/trace have effect only if DEBUG is defined. 94 */ 95#ifdef DEBUG 96#define ntfs_log_critical(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_CRITICAL,NULL,FORMAT,##ARGS) 97#define ntfs_log_error(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ERROR,NULL,FORMAT,##ARGS) 98#define ntfs_log_info(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_INFO,NULL,FORMAT,##ARGS) 99#define ntfs_log_perror(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PERROR,NULL,FORMAT,##ARGS) 100#define ntfs_log_progress(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PROGRESS,NULL,FORMAT,##ARGS) 101#define ntfs_log_quiet(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_QUIET,NULL,FORMAT,##ARGS) 102#define ntfs_log_verbose(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_VERBOSE,NULL,FORMAT,##ARGS) 103#define ntfs_log_warning(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_WARNING,NULL,FORMAT,##ARGS) 104#else 105#define ntfs_log_critical(FORMAT, ARGS...) 106#define ntfs_log_error(FORMAT, ARGS...) 107#define ntfs_log_info(FORMAT, ARGS...) 108#define ntfs_log_perror(FORMAT, ARGS...) 109#define ntfs_log_progress(FORMAT, ARGS...) 110#define ntfs_log_quiet(FORMAT, ARGS...) 111#define ntfs_log_verbose(FORMAT, ARGS...) 112#define ntfs_log_warning(FORMAT, ARGS...) 113 114#endif 115 116/* By default debug and trace messages are compiled into the program, 117 * but not displayed. 118 */ 119#ifdef DEBUG 120#define ntfs_log_debug(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_DEBUG,NULL,FORMAT,##ARGS) 121#define ntfs_log_trace(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_TRACE,NULL,FORMAT,##ARGS) 122#define ntfs_log_enter(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ENTER,NULL,FORMAT,##ARGS) 123#define ntfs_log_leave(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_LEAVE,NULL,FORMAT,##ARGS) 124#else 125#define ntfs_log_debug(FORMAT, ARGS...) 126#define ntfs_log_trace(FORMAT, ARGS...) 127#define ntfs_log_enter(FORMAT, ARGS...) 128#define ntfs_log_leave(FORMAT, ARGS...) 129#endif /* DEBUG */ 130 131#endif /* _LOGGING_H_ */ 132 133