当前位置: 首页>>代码示例>>Java>>正文


Java LogRecord.setSourceClassName方法代码示例

本文整理汇总了Java中java.util.logging.LogRecord.setSourceClassName方法的典型用法代码示例。如果您正苦于以下问题:Java LogRecord.setSourceClassName方法的具体用法?Java LogRecord.setSourceClassName怎么用?Java LogRecord.setSourceClassName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.logging.LogRecord的用法示例。


在下文中一共展示了LogRecord.setSourceClassName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: logThrowing

import java.util.logging.LogRecord; //导入方法依赖的package包/类
/**
 * Logs throwing of exceptions.
 * 
 * @param loggerName
 * @param thrown
 */
public static void logThrowing(String loggerName, Throwable thrown) {
	if (loggerName != null) {
		Logger logger = loggers.get(loggerName);
		if (logger != null) {
			Thread current = Thread.currentThread();
			int totalStackOffset = 2;
			StackTraceElement[] trace = current.getStackTrace();

			LogRecord logRecord = new LogRecord(Level.ALL, "Exception thrown!");

			if (trace.length >= totalStackOffset) {
				StackTraceElement caller = trace[totalStackOffset];
				logRecord.setSourceMethodName(caller.getMethodName());
				logRecord.setSourceClassName(caller.getClassName());
				int lineNumber = caller.getLineNumber();
				logRecord.setParameters(new Object[] { lineNumber });
				logRecord.setThrown(thrown);
			}
			logger.log(logRecord);
		}
	}
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:29,代码来源:Logging.java

示例2: error

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public void error(String s, Throwable e) {
    LogRecord lr = new LogRecord(Level.SEVERE, s);
    lr.setSourceClassName(log.getName());
    lr.setThrown(e);

    log.log(lr);
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:8,代码来源:JdkLoggingImpl.java

示例3: logMessage

import java.util.logging.LogRecord; //导入方法依赖的package包/类
/**
 * Logs a message to the logger with the given name. If there is no such logger, the log-message is ignored.
 * 
 * @param loggerName
 * @param message
 * @param level
 */
private static void logMessage(String loggerName, String message, Level level, int stackOffset) {
	if (loggerName == null) {
		return;
	}
	Logger logger = loggers.get(loggerName);
	if (logger == null) {
		System.out.println("Tried to log message to " + loggerName + " which isn't available");
		return;
	} else {
		LogRecord logRecord = new LogRecord(level, message);

		// if (!(level.intValue() < logger.getLevel().intValue() ||
		// logger.getLevel().intValue() == Level.OFF.intValue())) {
		// System.out.print();//Use breakpoint & debug mode to quickly find
		// where a message was logged from
		// }

		// this method is called from another method -- and the logger would
		// normally log "logMessage" as its caller, which is rather
		// unhelpful
		// -> go to the call stack and get the relevant message!

		Thread current = Thread.currentThread();
		int totalStackOffset = 2 + stackOffset;
		StackTraceElement[] trace = current.getStackTrace();
		if (trace.length >= totalStackOffset) {
			StackTraceElement caller = trace[totalStackOffset];
			logRecord.setSourceMethodName(caller.getMethodName() + " (Logger: " + loggerName + ")");
			logRecord.setSourceClassName(caller.getClassName());
			logRecord.setLoggerName(loggerName);
			int lineNumber = caller.getLineNumber();
			logRecord.setParameters(new Object[] { lineNumber });
		}

		logger.log(logRecord);
	}
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:45,代码来源:Logging.java

示例4: inferCaller

import java.util.logging.LogRecord; //导入方法依赖的package包/类
private void inferCaller( Class wrapperClass, LogRecord lrec )
{
    // Private method to infer the caller's class and method names

    // Get the stack trace.
    StackTraceElement stack[] = (new Throwable()).getStackTrace();
    StackTraceElement frame = null ;
    String wcname = wrapperClass.getName() ;
    String baseName = LogWrapperBase.class.getName() ;

    // The top of the stack should always be a method in the wrapper class,
    // or in this base class.
    // Search back to the first method not in the wrapper class or this class.
    int ix = 0;
    while (ix < stack.length) {
        frame = stack[ix];
        String cname = frame.getClassName();
        if (!cname.equals(wcname) && !cname.equals(baseName))  {
            break;
        }

        ix++;
    }

    // Set the class and method if we are not past the end of the stack
    // trace
    if (ix < stack.length) {
        lrec.setSourceClassName(frame.getClassName());
        lrec.setSourceMethodName(frame.getMethodName());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:LogWrapperBase.java

示例5: debug

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public void debug(String s) {
    LogRecord lr = new LogRecord(Level.FINE, s);
    lr.setSourceClassName(log.getName());

    log.log(lr);
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:7,代码来源:JdkLoggingImpl.java

示例6: warn

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public void warn(String s) {
    LogRecord lr = new LogRecord(Level.WARNING, s);
    lr.setSourceClassName(log.getName());

    log.log(lr);
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:7,代码来源:JdkLoggingImpl.java

示例7: error

import java.util.logging.LogRecord; //导入方法依赖的package包/类
public void error(String s) {
    LogRecord lr = new LogRecord(Level.SEVERE, s);
    lr.setSourceClassName(log.getName());

    log.log(lr);
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:7,代码来源:JdkLoggingImpl.java


注:本文中的java.util.logging.LogRecord.setSourceClassName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。