⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logging.c

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * A simple syslog logging handler.  Ignores colors. * * Returns:  -1  Error occurred *            0  Message wasn't logged *          num  Number of output characters */#ifdef HAVE_SYSLOG_Hint ntfs_log_handler_syslog(const char *function  __attribute__((unused)),	const char *file, __attribute__((unused)) int line, u32 level,	void *data __attribute__((unused)), const char *format, va_list args){	const int reason_size = 128;	static char *reason = NULL;	int ret = 0;	int olderr = errno;	if (level == NTFS_LOG_LEVEL_REASON) {		if (!reason)			reason = malloc(reason_size);		if (reason) {			memset(reason, 0, reason_size);			return vsnprintf(reason, reason_size, format, args);		} else {			/* Rather than call ourselves, just drop through */			level = NTFS_LOG_LEVEL_PERROR;			format = "Couldn't create reason";			args = NULL;			olderr = errno;		}	}	if ((ntfs_log.flags & NTFS_LOG_FLAG_ONLYNAME) &&	    (strchr(file, PATH_SEP)))		/* Abbreviate the filename */		file = strrchr(file, PATH_SEP) + 1;#if 0	/* FIXME: Implement this all. */	if (ntfs_log.flags & NTFS_LOG_FLAG_PREFIX)	/* Prefix the output */		ret += fprintf(stream, "%s", ntfs_log_get_prefix(level));	if (ntfs_log.flags & NTFS_LOG_FLAG_FILENAME)	/* Source filename */		ret += fprintf(stream, "%s ", file);	if (ntfs_log.flags & NTFS_LOG_FLAG_LINE)	/* Source line number */		ret += fprintf(stream, "(%d) ", line);	if ((ntfs_log.flags & NTFS_LOG_FLAG_FUNCTION) || /* Source function */	    (level & NTFS_LOG_LEVEL_TRACE))		ret += fprintf(stream, "%s(): ", function);	ret += vfprintf(stream, format, args);	if (level & NTFS_LOG_LEVEL_PERROR) {		if (reason)			ret += fprintf(stream, " : %s\n", reason);		else			ret += fprintf(stream, " : %s\n", strerror(olderr));	}#endif	vsyslog(LOG_NOTICE, format, args);	ret = 1; /* FIXME: caclulate how many bytes had been written. */	errno = olderr;	return ret;}#endif#endif /* __VISOPSYS__ *//** * ntfs_log_handler_fprintf - Basic logging handler * @function:	Function in which the log line occurred * @file:	File in which the log line occurred * @line:	Line number on which the log line occurred * @level:	Level at which the line is logged * @data:	User specified data, possibly specific to a handler * @format:	printf-style formatting string * @args:	Arguments to be formatted * * A simple logging handler.  This is where the log line is finally displayed. * It is more likely that you will want to set the handler to either * ntfs_log_handler_outerr or ntfs_log_handler_stderr. * * Note: For this handler, @data is a pointer to a FILE output stream. *       If @data is NULL, nothing will be displayed. * * Returns:  -1  Error occurred *            0  Message wasn't logged *          num  Number of output characters */int ntfs_log_handler_fprintf(const char *function, const char *logfile,	int line, u32 level, void *data, const char *format, va_list args){	const int reason_size = 128;	static char *reason = NULL;	int ret = 0;	int olderr = errno;	FILE *strm;	const char *col_prefix = NULL;	const char *col_suffix = NULL;	if (!data)		/* Interpret data as a FILE stream. */		return 0;	/* If it's NULL, we can't do anything. */	strm = (FILE*)data;	if (level == NTFS_LOG_LEVEL_REASON) {		if (!reason)			reason = malloc(reason_size);		if (reason) {			memset(reason, 0, reason_size);			return vsnprintf(reason, reason_size, format, args);		} else {			/* Rather than call ourselves, just drop through */			level = NTFS_LOG_LEVEL_PERROR;			format = "Couldn't create reason";			args = NULL;			olderr = errno;		}	}	if (ntfs_log.flags & NTFS_LOG_FLAG_COLOUR) {		/* Pick a colour determined by the log level */		switch (level) {			case NTFS_LOG_LEVEL_DEBUG:				col_prefix = col_green;				col_suffix = col_end;				break;			case NTFS_LOG_LEVEL_TRACE:				col_prefix = col_cyan;				col_suffix = col_end;				break;			case NTFS_LOG_LEVEL_WARNING:				col_prefix = col_yellow;				col_suffix = col_end;				break;			case NTFS_LOG_LEVEL_ERROR:			case NTFS_LOG_LEVEL_PERROR:				col_prefix = col_red;				col_suffix = col_end;				break;			case NTFS_LOG_LEVEL_CRITICAL:				col_prefix = col_redinv;				col_suffix = col_end;				break;		}	}	if (col_prefix)		ret += fprintf(strm, col_prefix);	if ((ntfs_log.flags & NTFS_LOG_FLAG_ONLYNAME) &&	    (strchr(logfile, PATH_SEP)))		/* Abbreviate the filename */		logfile = strrchr(logfile, PATH_SEP) + 1;	if (ntfs_log.flags & NTFS_LOG_FLAG_PREFIX)	/* Prefix the output */		ret += fprintf(strm, "%s", ntfs_log_get_prefix(level));	if (ntfs_log.flags & NTFS_LOG_FLAG_FILENAME)	/* Source filename */		ret += fprintf(strm, "%s ", logfile);	if (ntfs_log.flags & NTFS_LOG_FLAG_LINE)	/* Source line number */		ret += fprintf(strm, "(%d) ", line);	if ((ntfs_log.flags & NTFS_LOG_FLAG_FUNCTION) || /* Source function */	    (level & NTFS_LOG_LEVEL_TRACE))		ret += fprintf(strm, "%s(): ", function);	ret += vfprintf(strm, format, args);	if (level & NTFS_LOG_LEVEL_PERROR) {		if (reason)			ret += fprintf(strm, " : %s\n", reason);		else			ret += fprintf(strm, " : %s\n", strerror(olderr));	}	if (col_suffix)		ret += fprintf(strm, col_suffix);	fflush(strm);	errno = olderr;	return ret;}/** * ntfs_log_handler_null - Null logging handler (no output) * @function:	Function in which the log line occurred * @file:	File in which the log line occurred * @line:	Line number on which the log line occurred * @level:	Level at which the line is logged * @data:	User specified data, possibly specific to a handler * @format:	printf-style formatting string * @args:	Arguments to be formatted * * This handler produces no output.  It provides a way to temporarily disable * logging, without having to change the levels and flags. * * Returns:  0  Message wasn't logged */int ntfs_log_handler_null(const char *function __attribute__((unused)), const char *logfile __attribute__((unused)),	int line __attribute__((unused)), u32 level __attribute__((unused)), void *data __attribute__((unused)),	const char *format __attribute__((unused)), va_list args __attribute__((unused))){	return 0;}#ifndef __VISOPSYS__/** * ntfs_log_handler_stdout - All logs go to stdout * @function:	Function in which the log line occurred * @file:	File in which the log line occurred * @line:	Line number on which the log line occurred * @level:	Level at which the line is logged * @data:	User specified data, possibly specific to a handler * @format:	printf-style formatting string * @args:	Arguments to be formatted * * Display a log message to stdout. * * Note: For this handler, @data is a pointer to a FILE output stream. *       If @data is NULL, then stdout will be used. * * Note: This function calls ntfs_log_handler_fprintf to do the main work. * * Returns:  -1  Error occurred *            0  Message wasn't logged *          num  Number of output characters */int ntfs_log_handler_stdout(const char *function, const char *file,	int line, u32 level, void *data, const char *format, va_list args){	if (!data)		data = stdout;	return ntfs_log_handler_fprintf(function, file, line, level, data, format, args);}#endif /* __VISOPSYS__ *//** * ntfs_log_handler_outerr - Logs go to stdout/stderr depending on level * @function:	Function in which the log line occurred * @file:	File in which the log line occurred * @line:	Line number on which the log line occurred * @level:	Level at which the line is logged * @data:	User specified data, possibly specific to a handler * @format:	printf-style formatting string * @args:	Arguments to be formatted * * Display a log message.  The output stream will be determined by the log * level. * * Note: For this handler, @data is a pointer to a FILE output stream. *       If @data is NULL, the function ntfs_log_get_stream will be called * * Note: This function calls ntfs_log_handler_fprintf to do the main work. * * Returns:  -1  Error occurred *            0  Message wasn't logged *          num  Number of output characters */int ntfs_log_handler_outerr(const char *function, const char *logfile,	int line, u32 level, void *data, const char *format, va_list args){	if (!data)		data = ntfs_log_get_stream(level);	return ntfs_log_handler_fprintf(function, logfile, line, level, data, format, args);}#ifndef __VISOPSYS__/** * ntfs_log_handler_stderr - All logs go to stderr * @function:	Function in which the log line occurred * @file:	File in which the log line occurred * @line:	Line number on which the log line occurred * @level:	Level at which the line is logged * @data:	User specified data, possibly specific to a handler * @format:	printf-style formatting string * @args:	Arguments to be formatted * * Display a log message to stderr. * * Note: For this handler, @data is a pointer to a FILE output stream. *       If @data is NULL, then stdout will be used. * * Note: This function calls ntfs_log_handler_fprintf to do the main work. * * Returns:  -1  Error occurred *            0  Message wasn't logged *          num  Number of output characters */int ntfs_log_handler_stderr(const char *function, const char *file,	int line, u32 level, void *data, const char *format, va_list args){	if (!data)		data = stderr;	return ntfs_log_handler_fprintf(function, file, line, level, data, format, args);}/** * ntfs_log_parse_option - Act upon command line options * @option:	Option flag * * Delegate some of the work of parsing the command line.  All the options begin * with "--log-".  Options cause log levels to be enabled in @ntfs_log (the * global logging structure). * * Note: The "colour" option changes the logging handler. * * Returns:  TRUE  Option understood *          FALSE  Invalid log option */BOOL ntfs_log_parse_option(const char *option){	if (strcmp(option, "--log-debug") == 0) {		ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG);		return TRUE;	} else if (strcmp(option, "--log-verbose") == 0) {		ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);		return TRUE;	} else if (strcmp(option, "--log-quiet") == 0) {		ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET);		return TRUE;	} else if (strcmp(option, "--log-trace") == 0) {		ntfs_log_set_levels(NTFS_LOG_LEVEL_TRACE);		return TRUE;	} else if ((strcmp(option, "--log-colour") == 0) ||		   (strcmp(option, "--log-color") == 0)) {		ntfs_log_set_flags(NTFS_LOG_FLAG_COLOUR);		return TRUE;	}	ntfs_log_debug("Unknown logging option '%s'\n", option);	return FALSE;}#endif /* __VISOPSYS__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -