下面列出了java.util.logging.Level#intValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createIcon() {
Level[] levels = {Level.FINEST,//
Level.FINER,//
Level.FINE,//
Level.CONFIG,//
Level.INFO,//
Level.WARNING,//
Level.SEVERE,//
};
ArrayList<Icon> iconsList = new ArrayList<>();
for (Level l : levels) {
if (l.intValue() < levelIntValue) {
final Icon iconByLevel = LevelRenderer.getIconByLevel(l);
iconsList.add(iconByLevel);
}
}
icon = new CompoundIcon(iconsList);
}
public static int toServiceLevel(Level level) {
int val = level.intValue();
if (val >= Level.SEVERE.intValue()) {
return LogService.LOG_ERROR;
}
if (val >= Level.WARNING.intValue()) {
return LogService.LOG_WARNING;
}
if (val >= Level.INFO.intValue()) {
return LogService.LOG_INFO;
}
// Level.CONFIG
// Level.FINE
// Level.FINER
// Level.FINEST
return LogService.LOG_DEBUG;
}
private void setUpMyLevel() {
Level l = _myConfigLFH._defaultLevel;
for (LogConfig.L_LogFilterHandler.L_LogFilterConfigEntry fce : _myConfigLFH._logFCEList) {
if (fce._level.intValue() < l.intValue()) {
l = fce._level;
}
}
setLevel(l);
}
@Override
public boolean isLoggable(Level level) {
final Level threadLevel = threadMap.get(Thread.currentThread().getId());
if (threadLevel == null) return super.isLoggable(level);
final int levelValue = threadLevel.intValue();
final int offValue = Level.OFF.intValue();
if (level.intValue() < levelValue || levelValue == offValue) {
return false;
}
return true;
}
private LogStreamLog(LogStream stream, Level level) {
if ((stream != null) && (level != null)) {
/* if the stream or level is null, don't log any
* messages
*/
levelValue = level.intValue();
}
this.stream = stream;
}
/**
* Normalizes the given level to one of those supported by Selenium.
*
* @param level log level to normalize
* @return the selenium supported corresponding log level
*/
public static Level normalize(Level level) {
if (levelMap.containsKey(level.intValue())) {
return levelMap.get(level.intValue());
} else if (level.intValue() >= Level.SEVERE.intValue()) {
return Level.SEVERE;
} else if (level.intValue() >= Level.WARNING.intValue()) {
return Level.WARNING;
} else if (level.intValue() >= Level.INFO.intValue()) {
return Level.INFO;
} else {
return Level.FINE;
}
}
public static void enableInstances(Logger log, String msg, Level level) {
if (log == null) {
log = Logger.getLogger("TIMER"); // NOI18N
}
log.addHandler(new InstancesHandler(msg, level,2));
if (log.getLevel() == null || log.getLevel().intValue() > level.intValue()) {
log.setLevel(level);
}
}
private LogStreamLog(LogStream stream, Level level) {
if ((stream != null) && (level != null)) {
/* if the stream or level is null, don't log any
* messages
*/
levelValue = level.intValue();
}
this.stream = stream;
}
private LogStreamLog(LogStream stream, Level level) {
if ((stream != null) && (level != null)) {
/* if the stream or level is null, don't log any
* messages
*/
levelValue = level.intValue();
}
this.stream = stream;
}
public LevelLowerAcceptCondition(Level level) {
super();
this.level = level;
levelIntValue = level.intValue();
this.name = String.format("Level <%s", level.getName());
this.description = String.format("Level of log event is lower than %s", level.getName());
createIcon();
}
private boolean isError(Level level) {
int value = level.intValue();
return value <= Level.SEVERE.intValue() && value > Level.WARNING.intValue();
}
/**
* Implementation of {@link #unexpectedException(Logger, Class, String, Throwable)}.
*
* @param logger where to log the error, or {@code null} for inferring a default value from other arguments.
* @param classe the fully qualified class name where the error occurred, or {@code null} for inferring a default value from other arguments.
* @param method the method where the error occurred, or {@code null} for inferring a default value from other arguments.
* @param error the error, or {@code null} if none.
* @param level the logging level.
* @return {@code true} if the error has been logged, or {@code false} if the given {@code error}
* was null or if the logger does not log anything at the specified level.
*/
private static boolean unexpectedException(Logger logger, String classe, String method,
final Throwable error, final Level level)
{
/*
* Checks if loggable, inferring the logger from the classe name if needed.
*/
if (error == null) {
return false;
}
if (logger == null && classe != null) {
final int separator = classe.lastIndexOf('.');
final String paquet = (separator >= 1) ? classe.substring(0, separator-1) : "";
logger = getLogger(paquet);
}
if (logger != null && !logger.isLoggable(level)) {
return false;
}
/*
* The message is fetched using Exception.getMessage() instead than getLocalizedMessage()
* because in a client-server architecture, we want the locale on the server-side instead
* than the locale on the client side. See LocalizedException policy.
*/
final StringBuilder buffer = new StringBuilder(256).append(Classes.getShortClassName(error));
String message = error.getMessage(); // Targeted to system administrators (see above).
if (message != null) {
buffer.append(": ").append(message);
}
message = buffer.toString();
message = Exceptions.formatChainedMessages(null, message, error);
final LogRecord record = new LogRecord(level, message);
if (level.intValue() >= LEVEL_THRESHOLD_FOR_STACKTRACE) {
record.setThrown(error);
}
if (logger == null || classe == null || method == null) {
logger = inferCaller(logger, classe, method, error.getStackTrace(), record);
} else {
record.setSourceClassName(classe);
record.setSourceMethodName(method);
}
record.setLoggerName(logger.getName());
logger.log(record);
return true;
}
private void log(Level level, String message, Object... args) {
if (level.intValue() >= logThreshold) {
log.add(new StringEntry(id, ticker.read(), level, message, args));
}
}
/** Starts to listen on given log and collect parameters of messages that
* were send to it. This is supposed to be called at the beginning of a test,
* to get messages from the programs that use
* <a href="http://wiki.netbeans.org/wiki/view/FitnessViaTimersCounters">timers/counters</a>
* infrastructure. At the end one should call {@link #assertInstances}.
*
*
* @param log logger to listen on, if null, it uses the standard timers/counters one
* @param msg name of messages to collect, if null, all messages will be recorded
* @param level level of messages to record
* @since 1.44
*/
public static void enableInstances(Logger log, String msg, Level level) {
if (log == null) {
log = Logger.getLogger("TIMER"); // NOI18N
}
log.addHandler(new InstancesHandler(msg, level));
if (log.getLevel() == null || log.getLevel().intValue() > level.intValue()) {
log.setLevel(level);
}
}
/**
* Store a message in SERVER log
* @param level Message Level
* @param message Message content
*/
public final static synchronized void error(Level level, String message) {
if (!errorEnabled || level.intValue()<loglevel.intValue()) return;
logger.store(ERROR, level, new StringBuilder(message));
}
/**
* Store a message in SERVICE log
* @param level Message Level
* @param message Message content
*/
public final static synchronized void service(Level level, String message) {
if (!serviceEnabled || level.intValue()<loglevel.intValue()) return;
logger.store(SERVICE, level, new StringBuilder(message));
}
/**
* Check if the logger is above of the level of detail given
* @see java.util.logging.Level
*
* @param level logging level
* @return true if level is above the given one
*/
public boolean levelAbove(final Level level) {
return getLevel().intValue() > level.intValue();
}
/**
* Check if the logger is above or equal to the level
* of detail given
* @see java.util.logging.Level
*
* The higher the level, the more severe the warning
*
* @param level logging level
* @return true if level is above the given one
*/
public boolean levelCoarserThanOrEqual(final Level level) {
return getLevel().intValue() >= level.intValue();
}
/**
* Create new instance.
*
* @param level comparison level.
*/
public GreaterThanEqualsRule(final Level level) {
super();
newLevelInt = level.intValue();
}
/**
* Constructs an ExceptionLogHandler that throws a runtime exception at and above the specified
* log level.
*
* @param fatalLevel the minimum log level for which to throw an exception.
*/
public ExceptionLogHandler(Level fatalLevel) {
this.fatalLevel = fatalLevel.intValue();
}