當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。