1N/A * logging.c - Centralised logging. Part of the Linux-NTFS project. 1N/A * Copyright (c) 2005 Richard Russon 1N/A * modify it under the terms of the GNU General Public License as published 1N/A * by the Free Software Foundation; either version 2 of the License, or 1N/A * (at your option) any later version. 1N/A * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 1N/A * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A * GNU General Public License for more details. 1N/A * You should have received a copy of the GNU General Public License 1N/A * along with this program (in the main directory of the Linux-NTFS 1N/A * distribution in the file COPYING); if not, write to the Free Software 1N/A * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1N/A/* Colour prefixes and a suffix */ 1N/A * struct ntfs_logging - Control info for the logging system 1N/A * @levels: Bitfield of logging levels 1N/A * @flags: Flags which affect the output style 1N/A * @handler: Function to perform the actual logging 1N/A * ntfs_log - This struct controls all the logging in the library and tools. 1N/A * ntfs_log_get_levels - Get a list of the current logging levels 1N/A * Find out which logging levels are enabled. 1N/A * Returns: Log levels in a 32-bit field 1N/A * ntfs_log_set_levels - Enable extra logging levels 1N/A * @levels: 32-bit field of log levels to set 1N/A * Enable one or more logging levels. 1N/A * The logging levels are named: NTFS_LOG_LEVEL_*. 1N/A * Returns: Log levels that were enabled before the call 1N/A * ntfs_log_clear_levels - Disable some logging levels 1N/A * @levels: 32-bit field of log levels to clear 1N/A * Disable one or more logging levels. 1N/A * The logging levels are named: NTFS_LOG_LEVEL_*. 1N/A * Returns: Log levels that were enabled before the call 1N/A * ntfs_log_get_flags - Get a list of logging style flags 1N/A * Find out which logging flags are enabled. 1N/A * Returns: Logging flags in a 32-bit field 1N/A * ntfs_log_set_flags - Enable extra logging style flags 1N/A * @flags: 32-bit field of logging flags to set 1N/A * Enable one or more logging flags. 1N/A * The log flags are named: NTFS_LOG_LEVEL_*. 1N/A * Returns: Logging flags that were enabled before the call 1N/A * ntfs_log_clear_flags - Disable some logging styles 1N/A * @flags: 32-bit field of logging flags to clear 1N/A * Disable one or more logging flags. 1N/A * The log flags are named: NTFS_LOG_LEVEL_*. 1N/A * Returns: Logging flags that were enabled before the call 1N/A * ntfs_log_get_stream - Default output streams for logging levels 1N/A * By default, urgent messages are sent to "stderr". 1N/A * Other messages are sent to "stdout". 1N/A * Returns: "string" Prefix to be used 1N/A * ntfs_log_get_prefix - Default prefixes for logging levels 1N/A * @level: Log level to be prefixed 1N/A * Prefixing the logging output can make it easier to parse. 1N/A * Returns: "string" Prefix to be used 1N/A * ntfs_log_set_handler - Provide an alternate logging handler 1N/A * @handler: function to perform the logging 1N/A * This alternate handler will be called for all future logging requests. 1N/A * If no @handler is specified, logging will revert to the default handler. 1N/A * ntfs_log_redirect - Pass on the request to the real handler 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @...: Arguments to be formatted 1N/A * This is just a redirector function. The arguments are simply passed to the 1N/A * main logging handler (as defined in the global logging struct @ntfs_log). 1N/A * Returns: -1 Error occurred 1N/A * 0 Message wasn't logged 1N/A * num Number of output characters 1N/A * ntfs_log_handler_syslog - syslog logging handler 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @args: Arguments to be formatted 1N/A * A syslog logging handler. Ignores colors and truncates output after 512 1N/A * Returns: -1 Error occurred 1N/A * 0 Message wasn't logged 1N/A * num Number of output characters 1N/A /* Prefix the output */ 1N/A /* Source filename */ 1N/A /* Source line number */ 1N/A /* Source function */ 1N/A /* Message itself */ 1N/A * ntfs_log_handler_fprintf - Basic logging handler 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @args: Arguments to be formatted 1N/A * A simple logging handler. This is where the log line is finally displayed. 1N/A * It is more likely that you will want to set the handler to either 1N/A * ntfs_log_handler_outerr or ntfs_log_handler_stderr. 1N/A * Note: For this handler, @data is a pointer to a FILE output stream. 1N/A * If @data is NULL, nothing will be displayed. 1N/A * Returns: -1 Error occurred 1N/A * 0 Message wasn't logged 1N/A * num Number of output characters 1N/A if (!
data)
/* Interpret data as a FILE stream. */ 1N/A return 0;
/* If it's NULL, we can't do anything. */ 1N/A /* Pick a colour determined by the log level */ 1N/A * ntfs_log_handler_null - Null logging handler (no output) 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @args: Arguments to be formatted 1N/A * This handler produces no output. It provides a way to temporarily disable 1N/A * logging, without having to change the levels and flags. 1N/A * Returns: 0 Message wasn't logged 1N/A * ntfs_log_handler_stdout - All logs go to stdout 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @args: Arguments to be formatted 1N/A * Display a log message to stdout. 1N/A * Note: For this handler, @data is a pointer to a FILE output stream. 1N/A * If @data is NULL, then stdout will be used. 1N/A * Note: This function calls ntfs_log_handler_fprintf to do the main work. 1N/A * Returns: -1 Error occurred 1N/A * 0 Message wasn't logged 1N/A * num Number of output characters 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @args: Arguments to be formatted 1N/A * Display a log message. The output stream will be determined by the log 1N/A * Note: For this handler, @data is a pointer to a FILE output stream. 1N/A * If @data is NULL, the function ntfs_log_get_stream will be called 1N/A * Note: This function calls ntfs_log_handler_fprintf to do the main work. 1N/A * Returns: -1 Error occurred 1N/A * 0 Message wasn't logged 1N/A * num Number of output characters 1N/A * ntfs_log_handler_stderr - All logs go to stderr 1N/A * @function: Function in which the log line occurred 1N/A * @file: File in which the log line occurred 1N/A * @line: Line number on which the log line occurred 1N/A * @level: Level at which the line is logged 1N/A * @data: User specified data, possibly specific to a handler 1N/A * @format: printf-style formatting string 1N/A * @args: Arguments to be formatted 1N/A * Display a log message to stderr. 1N/A * Note: For this handler, @data is a pointer to a FILE output stream. 1N/A * If @data is NULL, then stdout will be used. 1N/A * Note: This function calls ntfs_log_handler_fprintf to do the main work. 1N/A * Returns: -1 Error occurred 1N/A * 0 Message wasn't logged 1N/A * num Number of output characters 1N/A * ntfs_log_parse_option - Act upon command line options 1N/A * @option: Option flag 1N/A * Delegate some of the work of parsing the command line. All the options begin 1N/A * with "--log-". Options cause log levels to be enabled in @ntfs_log (the 1N/A * global logging structure). 1N/A * Note: The "colour" option changes the logging handler. 1N/A * Returns: TRUE Option understood 1N/A * FALSE Invalid log option