Java Code Examples for java.util.logging.Level.SEVERE

The following are Jave code examples for showing how to use SEVERE of the java.util.logging.Level class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: LoggingTest.java   View Source Code Vote up 6 votes
public void testFmting() throws Exception {
    Logger log = Logger.getLogger(getName());
    
    LogRecord rec = new LogRecord(Level.SEVERE, "LOG_SevereMsg");
    rec.setResourceBundle(ResourceBundle.getBundle("org.netbeans.junit.TestBundle"));
    rec.setParameters(new Object[] { "Very" });
    log.log(rec);

    File f = new File(getWorkDir(), getName() + ".log");
    assertEquals("Log file exists", true, f.exists());

    byte[] arr = new byte[(int)f.length()];
    FileInputStream is = new FileInputStream(f);
    int l = is.read(arr);
    assertEquals(l, arr.length);

    String s = new String(arr);
    if (s.indexOf("Important message Very") == -1) {
        fail("There should the message\n" + s);
    }
}
 
Example 2
Project: incubator-netbeans   File: NbErrorManager.java   View Source Code Vote up 6 votes
/** @return the severity of the exception */
Level getSeverity() {
    if (severity != null) {
        return severity;
    }
    
    LogRecord[] anns = (arrAll != null) ? arrAll : arr;
    for (int i = 0; i < anns.length; i++) {
        Level s = anns[i].getLevel();
        if (severity == null || s.intValue() > severity.intValue()) {
            severity = s;
        }
    }
    
    if (severity == null || severity == Level.ALL) {
        // no severity specified, assume this is an error
        severity = t instanceof Error ? Level.SEVERE : Level.WARNING;
    }
    
    return severity;
}
 
Example 3
Project: incubator-netbeans   File: InstallerReadPageTest.java   View Source Code Vote up 6 votes
@RandomlyFails // NB-Core-Build #7964
public void testSendLogWithException() throws Exception {
    Logger uiLogger = Logger.getLogger(Installer.UI_LOGGER_NAME);
    LogRecord log1 = new LogRecord(Level.SEVERE, "TESTING MESSAGE");
    LogRecord log2 = new LogRecord(Level.SEVERE, "TESTING MESSAGE");
    LogRecord log3 = new LogRecord(Level.SEVERE, "NO EXCEPTION LOG");
    LogRecord log4 = new LogRecord(Level.INFO, "INFO");
    Throwable t1 = new NullPointerException("TESTING THROWABLE");
    Throwable t2 = new UnknownError("TESTING ERROR");
    log1.setThrown(t1);
    log2.setThrown(t2);
    log4.setThrown(t2);
    Installer installer = Installer.findObject(Installer.class, true);
    assertNotNull(installer);
    installer.restored();
    uiLogger.log(log1);
    uiLogger.log(log2);
    uiLogger.log(log3);
    UIHandler.waitFlushed();
    if (Installer.getThrown() == null) {
        fail("Exception should be found in the log");
    }
    
    doEncodingTest("UTF-8", "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'></meta>");
}
 
Example 4
Project: AppRTC-Android   File: Logging.java   View Source Code Vote up 6 votes
public static void log(Severity severity, String tag, String message) {
  if (loggingEnabled) {
    nativeLog(severity.ordinal(), tag, message);
    return;
  }

  // Fallback to system log.
  Level level;
  switch (severity) {
    case LS_ERROR:
      level = Level.SEVERE;
      break;
    case LS_WARNING:
      level = Level.WARNING;
      break;
    case LS_INFO:
      level = Level.INFO;
      break;
    default:
      level = Level.FINE;
      break;
  }
  fallbackLogger.log(level, tag + ": " + message);
}
 
Example 5
Project: SamaGamesAPI   File: SamaGamesAPI.java   View Source Code Vote up 6 votes
public void slackLog(Level level, SlackMessage message)
{
    String color;

    if (level == Level.FINE)
        color = "#2FA44F";
    else if (level == Level.WARNING)
        color = "#DE9E31";
    else if (level == Level.SEVERE)
        color = "#D50200";
    else
        color = "#28D7E5";

    try
    {
        this.getSlackLogsPublisher().push(new SlackAttachment("").color(color).text(message));
    }
    catch (IOException ignored) {}
}
 
Example 6
Project: litiengine   File: ConsoleLogHandler.java   View Source Code Vote up 5 votes
private static Color getColor(Level level) {
  if (level == Level.SEVERE) {
    return Color.RED;
  } else if (level == Level.WARNING) {
    return Color.ORANGE;
  } else
    return Color.LIGHT_GRAY;
}
 
Example 7
Project: incubator-netbeans   File: LogRecordsTest.java   View Source Code Vote up 5 votes
private static Level randomLevel(Random r) {
    int lev = r.nextInt(1100);
    if (lev >= Level.SEVERE.intValue()) return Level.SEVERE;
    if (lev >= Level.WARNING.intValue()) return Level.WARNING;
    if (lev >= Level.INFO.intValue()) return Level.INFO;
    if (lev >= Level.CONFIG.intValue()) return Level.CONFIG;
    if (lev >= Level.FINE.intValue()) return Level.FINE;
    if (lev >= Level.FINER.intValue()) return Level.FINER;
    if (lev >= Level.FINEST.intValue()) return Level.FINEST;
    return Level.OFF;
}
 
Example 8
Project: AlphaLibary   File: AddonLogger.java   View Source Code Vote up 5 votes
public void log(Level level, String msg) {
    StringBuilder builder = new StringBuilder();
    builder.append(PREFIX);

    if (level == Level.INFO) {
        builder.append(INFO);
    }

    if (level == Level.SEVERE) {
        builder.append(ERROR);
    }
    builder.append(" ").append(msg);

    System.out.println(builder.toString());
}
 
Example 9
Project: Kyoko   File: ColoredFormatter.java   View Source Code Vote up 5 votes
private String getColor(Level l) {
    if (l == Level.SEVERE) // why that's not enum ;/
        return ERROR_COLOR;
    else if (l == Level.WARNING)
        return WARNING_COLOR;
    else if (l == Level.INFO)
        return INFO_COLOR;
    else
        return DEBUG_COLOR;
}
 
Example 10
Project: incubator-netbeans   File: InstallerTest.java   View Source Code Vote up 5 votes
public void testCreateMessageIssue160019() throws IOException {//ignore annotations
    final List<LogRecord> logs = new ArrayList<LogRecord>();
    ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
    Exception rootExc = new NullPointerException("root");
    Exceptions.attachMessage(rootExc, "annotation message");
    LogRecord rec = new LogRecord(Level.SEVERE, "test");
    rec.setThrown(rootExc);
    LogRecords.write(bos, rec);
    bos.close();
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    LogRecords.scan(bis, new Handler() {

        @Override
        public void publish(LogRecord record) {
            logs.add(record);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });
    bis.close();

    assertEquals(1, logs.size());
    Throwable thrown = logs.get(0).getThrown();
    assertEquals("thrown is annotated", "annotation message", thrown.getCause().getMessage());
    String message = Installer.createMessage(thrown);
    assertEquals("annontation should be ignored", "NullPointerException: root", message);
}
 
Example 11
Project: aws-codecommit-trigger-plugin   File: Log.java   View Source Code Vote up 5 votes
private void write(final Level level, final String message, final String jobName, final Object... args) {
    for (int i = 0; i < args.length; i++) {
        if (args[i] instanceof SQSTriggerQueue) {
            args[i] = ((SQSTriggerQueue) args[i]).getUrl();
        }
        else if (args[i] instanceof Throwable) {
            args[i] = ExceptionUtils.getStackTrace((Throwable)args[i]);
        }
    }

    StringBuilder source = new StringBuilder();
    if (this.autoFormat) {
        final String id = String.format("%06X", Thread.currentThread().getId());
        source
            .append("[").append(ClassUtils.getAbbreviatedName(this.clazz, 1)).append("]")
            .append("[thread-").append(id).append("]");
        if (StringUtils.isNotBlank(jobName)) {
            source.append("[job-").append(jobName).append("]");
        }
    }

    String msg = String.format(message, args);
    if (level == Level.CONFIG) {
        msg = "[DEBUG] " + msg;
    } else if (level == Level.SEVERE) {
        msg = "[ERROR] " + msg;
    }

    this.logger.logp(level, source.toString(), "", msg);
    if (this.streamHandler != null) {
        this.streamHandler.flush();
    }
}
 
Example 12
Project: DIA-Umpire-Maven   File: DocumentHandler.java   View Source Code Vote up 5 votes
/**
 *
 */
public void publish(LogRecord record) {
    if (!isLoggable(record)) {
        return;
    }

    String message;

    try {
        message = getFormatter().format(record);
    } catch (Exception exception) {
        reportError(null, exception, ErrorManager.FORMAT_FAILURE);
        return;
    }

    synchronized (textPane) {
        if (textPane.getDocument().getLength() >= MAXIMUM_DOCUMENT_SIZE) {
            // Delete the contents of the text pane.
            textPane.setText("");
        }

        try {
            if (record.getLevel() == Level.SEVERE) {
                textPane.getDocument().insertString(textPane.getDocument().getLength(), message, severStyle);
            } else {
                textPane.getDocument().insertString(textPane.getDocument().getLength(), message, infoStyle);
            }
            textPane.setCaretPosition(textPane.getDocument().getLength());
        } catch (Exception ex) {
            reportError(null, ex, ErrorManager.WRITE_FAILURE);
        }
    }

}
 
Example 13
Project: myfaces-trinidad   File: RenderKitTestCase.java   View Source Code Vote up 5 votes
@Override
public void publish(LogRecord record)
{
  if (record.getLevel() == Level.SEVERE)
  {
    String message = (new SimpleFormatter()).format(record);
    _result.addError(BaseTest.this,
                     new AssertionFailedError(message));
  }
}
 
Example 14
Project: generator_mybatis   File: JdkLoggingImpl.java   View Source Code Vote up 5 votes
public void error(String s, Throwable e) {
    LogRecord lr = new LogRecord(Level.SEVERE, s);
    lr.setSourceClassName(log.getName());
    lr.setThrown(e);

    log.log(lr);
}
 
Example 15
Project: NameTagChanger   File: ChannelPacketHandler.java   View Source Code Vote up 5 votes
@Override
protected void logMessage(Level level, String message, Exception e) {
    if (level == Level.SEVERE) {
        System.err.println("[NameTagChanger] " + message);
    } else {
        NameTagChanger.INSTANCE.printMessage(message);
    }
    if (e != null) {
        e.printStackTrace();
    }
}
 
Example 16
Project: MybatisGeneatorUtil   File: JdkLoggingImpl.java   View Source Code Vote up 5 votes
public void error(String s, Throwable e) {
    LogRecord lr = new LogRecord(Level.SEVERE, s);
    lr.setSourceClassName(log.getName());
    lr.setThrown(e);

    log.log(lr);
}
 
Example 17
Project: Elasticsearch   File: JdkESLogger.java   View Source Code Vote up 4 votes
@Override
protected void internalError(String msg, Throwable cause) {
    LogRecord record = new ESLogRecord(Level.SEVERE, msg);
    record.setThrown(cause);
    logger.log(record);
}
 
Example 18
Project: Java-EX   File: Log.java   View Source Code Vote up 4 votes
public SubLog error() {
  return new SubLog(Level.SEVERE);
}
 
Example 19
Project: incubator-netbeans   File: InstanceCookieViaNodeTest.java   View Source Code Vote up 4 votes
@Override
protected Level logLevel() {
    return Level.SEVERE;
}
 
Example 20
Project: incubator-netbeans   File: LogRecords.java   View Source Code Vote up 4 votes
static Level parseLevel(String lev) {
    return "USER".equals(lev) ? Level.SEVERE : Level.parse(lev);
}