java.util.logging.Level#WARNING源码实例Demo

下面列出了java.util.logging.Level#WARNING 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mongodb-async-driver   文件: JulLogTest.java
/**
 * Test for the {@link AbstractLog#warn(String)} method.
 */
@Test
public void testWarnString() {
    final String method = "testWarnString";
    final String messsage = "Warning Message";
    final Level level = Level.WARNING;

    myTestLog.warn(messsage);

    final List<LogRecord> records = myCaptureHandler.getRecords();
    assertThat(records.size(), is(1));

    final LogRecord record = records.get(0);
    assertThat(record.getLevel(), is(level));
    assertThat(record.getLoggerName(), is(JulLogTest.class.getName()));
    assertThat(record.getMessage(), is(messsage));
    assertThat(record.getSourceClassName(), is(JulLogTest.class.getName()));
    assertThat(record.getSourceMethodName(), is(method));
    assertThat(record.getThreadID(), is((int) Thread.currentThread()
            .getId()));
    assertThat(record.getThrown(), nullValue());
}
 
源代码2 项目: windup   文件: FernflowerJDKLogger.java
private Level getLevel(Severity severity)
{
    switch (severity)
    {
    case TRACE:
        return Level.FINE;
    case INFO:
        return Level.INFO;
    case WARN:
        return Level.WARNING;
    case ERROR:
        return Level.SEVERE;
    default:
        return Level.INFO;
    }
}
 
源代码3 项目: netbeans   文件: LoggingExceptionTest.java
public void testLoggedExceptionIsPrinted() throws Exception {
    Exception ex = new IOException("Ahoj");
    LogRecord rec = new LogRecord(Level.WARNING, "Cannot process {0}");
    rec.setThrown(ex);
    rec.setParameters(new Object[] { "Jardo" });
    Logger.getLogger("global").log(rec);
    
    File[] arr = getWorkDir().listFiles();
    assertEquals("One log file", 1, arr.length);
    String s = LoggingTest.readFile(arr[0]);
    
    if (s.indexOf("Ahoj") == -1) {
        fail("There needs to be 'Ahoj':\n" + s);
    }
    if (s.indexOf("Jardo") == -1) {
        fail("There needs to be 'Jardo':\n" + s);
    }
    if (s.indexOf("testLoggedExceptionIsPrinted") == -1) {
        fail("There needs to be name of the method:\n" + s);
    }
}
 
源代码4 项目: knox   文件: JdkMessageLogger.java
private static Level toLevel( final MessageLevel level ) {
  switch( level ) {
    case FATAL: return Level.SEVERE;
    case ERROR: return Level.SEVERE;
    case WARN: return Level.WARNING;
    case INFO: return Level.INFO;
    case DEBUG: return Level.FINE;
    case TRACE: return Level.FINEST;
    default: return Level.OFF;
  }
}
 
源代码5 项目: netbeans   文件: ProjectOpTest.java
public void testProjectOpError() throws Exception {
    LogRecord rec = new LogRecord(Level.WARNING, "UI_CLOSED_PROJECTS");
    rec.setParameters(new Object[] {
        "kuk", "buch", 
        "org.netbeans.modules.xml.schema.model/1"
    });
    
    ProjectOp op = ProjectOp.valueOf(rec);
    assertNull("Not recognized log", op);
}
 
源代码6 项目: symja_android_library   文件: L4MLogger.java
/**
 * Make a formated info log
 *
 * @param fmt
 *            format specification
 * @param args
 *            objects to log
 */
public void info(final String fmt, final Object... args) {
	String msg = null;
	if (null != fmt) {
		try {
			msg = String.format(fmt, args);
			super.log(Level.INFO, msg);
		} catch (IllegalFormatConversionException e) {
			msg = "wrong formated logging: " + e.getMessage();
			super.log(Level.WARNING, msg);
		}
	} else {
		error("no format string specified for: " + Arrays.toString(args));
	}
}
 
源代码7 项目: glowroot   文件: JavaLoggingIT.java
@Override
public void transactionMarker() {
    logger.log(new LogRecord(Level.FINEST, "vwx__"));
    logger.log(new LogRecord(Level.FINER, "wxy__"));
    logger.log(new LogRecord(Level.FINE, "xyz__"));
    logger.log(new LogRecord(Level.CONFIG, "bcd__"));
    logger.log(new LogRecord(Level.INFO, "cde__"));
    LogRecord lr = new LogRecord(Level.WARNING, "def__");
    lr.setLoggerName(logger.getName()); // test logger name
    logger.log(lr);
    logger.log(new LogRecord(Level.SEVERE, "efg__"));
}
 
源代码8 项目: sis   文件: CalcAddins.java
/**
 * Reports an exception. This is used if an exception occurred in a method that can not return
 * a {@link String} instance. This method logs the stack trace at {@link Level#WARNING}.
 *
 * @param method     the method from which an exception occurred.
 * @param exception  the exception.
 */
final void reportException(final String method, final Exception exception) {
    final Logger logger = getLogger();
    final LogRecord record = new LogRecord(Level.WARNING, getLocalizedMessage(exception));
    record.setLoggerName(logger.getName());
    record.setSourceClassName(getClass().getName());
    record.setSourceMethodName(method);
    record.setThrown(exception);
    logger.log(record);
}
 
源代码9 项目: netbeans   文件: WindowManagerImpl.java
/** Weaker form of assertion to control if client's code is calling
 * winsys from ED thread. Level of logged exception is lower if
 * assertions are disabled (for releases etc).
 */
static void warnIfNotInEDT () {
    Level level = assertsEnabled ? Level.WARNING : Level.FINE;
    if(!SwingUtilities.isEventDispatchThread()) {
        // tries to catch known JDK problem, SwingUtilities.isEventDispatchThread()
        // returns false even if it *is* in ED thread.
        // if we find "java.awt.EventDispatchThread" stack line, it's probable
        // that we hit this JDK problem (see links below)
        boolean isJDKProblem = false;
        StackTraceElement[] elems = Thread.currentThread().getStackTrace();
        for (StackTraceElement elem : elems) {
            if ("java.awt.EventDispatchThread".equals(elem.getClassName())) {
                isJDKProblem = true;
                break;
            }
        }

        if (!isJDKProblem) {
            // problem somewhere in NetBeans modules' code
            Logger.getLogger(WindowManagerImpl.class.getName()).log(level, null,
                    new java.lang.IllegalStateException(
                    "Problem in some module which uses Window System: "
                    + ASSERTION_ERROR_MESSAGE));
        } else {
            // probably known problem in JDK
            Logger.getLogger(WindowManagerImpl.class.getName()).log(level, null,
                    new java.lang.IllegalStateException(
                    "Known problem in JDK occurred. If you are interested, vote and report at:\n" +
                    "http://bugs.sun.com/view_bug.do?bug_id=6424157, http://bugs.sun.com/view_bug.do?bug_id=6553239 \n" +
                    "Also see related discussion at http://www.netbeans.org/issues/show_bug.cgi?id=90590"));
        }
    }
}
 
源代码10 项目: openwebbeans-meecrowave   文件: Log4j2Logger.java
private Level fromL4J(final org.apache.logging.log4j.Level l) {
    Level l2 = null;
    switch (l.getStandardLevel()) {
        case ALL:
            l2 = Level.ALL;
            break;
        case FATAL:
            l2 = Level.SEVERE;
            break;
        case ERROR:
            l2 = Level.SEVERE;
            break;
        case WARN:
            l2 = Level.WARNING;
            break;
        case INFO:
            l2 = Level.INFO;
            break;
        case DEBUG:
            l2 = Level.FINE;
            break;
        case OFF:
            l2 = Level.OFF;
            break;
        case TRACE:
            l2 = Level.FINEST;
            break;
        default:
            l2 = Level.FINE;
    }
    return l2;
}
 
源代码11 项目: beam   文件: LogRecordMatcherTest.java
@Test
public void testLevelMismatch() {
  LogRecord record = new LogRecord(Level.WARNING, "abc");
  try {
    assertThat(record, LogRecordMatcher.hasLog(Level.CONFIG, ""));
  } catch (AssertionError e) {
    return;
  }

  fail("Expected exception not thrown");
}
 
源代码12 项目: roboconf-platform   文件: RoboconfLogFormatter.java
/**
 * @return the maximum length of a log level
 */
static int findMaxLevelLength() {

	Level[] levels = new Level[] {
			Level.ALL, Level.CONFIG, Level.FINE,
			Level.FINER, Level.FINEST, Level.INFO,
			Level.OFF, Level.SEVERE, Level.WARNING
	};

	int result = -1;
	for( Level level : levels )
		result = Math.max( result, level.toString().length());

	return result;
}
 
源代码13 项目: birt   文件: JavaUtilLoggerImpl.java
public void log( Exception ex )
{
	if ( logger.isLoggable( Level.WARNING ) )
	{
		LogRecord lr = new LogRecord( Level.WARNING, "Exception" ); //$NON-NLS-1$
		lr.setThrown( ex );
		String[] rt = inferCaller( );
		lr.setSourceClassName( rt[0] );
		lr.setSourceMethodName( rt[1] );
		logger.log( lr );
	}
}
 
源代码14 项目: cxf   文件: AbstractDelegatingLogger.java
public void warning(String msg) {
    if (isLoggable(Level.WARNING)) {
        LogRecord lr = new LogRecord(Level.WARNING, msg);
        doLog(lr);
    }
}
 
源代码15 项目: triplea   文件: ChatHandlerTest.java
private LogRecord newLoggableLogRecordWithMultipleLines() {
  return new LogRecord(Level.WARNING, "message\nmessage2\n");
}
 
源代码16 项目: moleculer-java   文件: FastLogFormatter.java
public String format(LogRecord record) {
	line.setLength(0);
	line.append('[');
	line.append(Instant.ofEpochMilli(record.getMillis()).toString());

	final Level l = record.getLevel();
	line.append("] ");
	if (l == Level.SEVERE) {
		line.append(SEVERE);
	} else if (l == Level.WARNING) {
		line.append(WARNING);
	} else if (l == Level.INFO) {
		line.append(INFO);
	} else if (l == Level.CONFIG) {
		line.append(CONFIG);
	} else if (l == Level.FINE) {
		line.append(FINE);
	} else if (l == Level.FINER) {
		line.append(FINER);
	} else {
		line.append(FINEST);
	}

	String className = record.getSourceClassName();
	int n;
	if (className == null) {
		className = "unknown";
	} else {
		n = className.lastIndexOf('$');
		if (n > -1) {
			className = className.substring(0, n);
		}
	}
	line.append(className);
	n = line.length();
	if (n > position || position - n > 30) {
		position = n;
	}
	n = 1 + position - n;
	if (n > 0) {
		for (int i = 0; i < n; i++) {
			line.append(' ');
		}
	}
	line.append(formatMessage(record));
	line.append(BREAK);

	// Dump error
	final Throwable cause = record.getThrown();
	if (cause != null) {
		StringBuilder errors = new StringBuilder(256);
		n = appendMessages(errors, cause);
		String trace = errors.toString().trim();
		if (!trace.isEmpty()) {
			for (int i = 0; i < n; i++) {
				line.append('-');
			}
			line.append(BREAK);
			line.append(trace);
			line.append(BREAK);
			for (int i = 0; i < n; i++) {
				line.append('-');
			}
			line.append(BREAK);
		}
		line.append("Trace: ");
		line.append(cause.toString());
		line.append(BREAK);
		StackTraceElement[] array = cause.getStackTrace();
		if (array != null && array.length > 0) {
			for (n = 0; n < array.length; n++) {
				line.append("-> [");
				line.append(n);
				line.append("] ");
				line.append(array[n]);
				line.append(BREAK);
			}
		}
	}
	return line.toString();
}
 
源代码17 项目: netbeans   文件: AntArtifactTest.java
protected @Override Level logLevel() {
    return Level.WARNING;
}
 
源代码18 项目: netbeans   文件: DataMoveTest.java
@Override
protected Level logLevel() {
    return Level.WARNING;
}
 
源代码19 项目: sis   文件: StaxDataStore.java
/**
 * Forwards StAX warnings to {@link DataStore} listeners.
 * This method is invoked by {@link XMLStreamReader} when needed.
 *
 * @param message    the message to put in a logging record.
 * @param errorType  ignored.
 * @param info       ignored.
 * @param location   ignored.
 */
@Override
public void report(String message, String errorType, Object info, Location location) {
    final LogRecord record = new LogRecord(Level.WARNING, message);
    record.setSourceClassName(StaxDataStore.this.getClass().getCanonicalName());
    // record.setLoggerName(…) will be invoked by 'listeners' with inferred name.
    listeners.warning(record);
}
 
源代码20 项目: symja_android_library   文件: L4MLogger.java
/**
 * Make a warning log.
 *
 * @param msg
 *            message to log
 */
@Override
public void warning(final String msg) {
	super.log(Level.WARNING, msg);
}