Java Code Examples for java.util.logging.Level#equals()
The following examples show how to use
java.util.logging.Level#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggingOutputStream.java From cactoos with MIT License | 6 votes |
@Override public void write(final byte[] buf, final int offset, final int len) throws IOException { final Instant start = Instant.now(); this.origin.write(buf, offset, len); final Instant end = Instant.now(); final long millis = Duration.between(start, end).toMillis(); this.bytes.getAndAdd(len); this.time.getAndAdd(millis); final Level level = this.logger.getLevel(); if (!level.equals(Level.INFO)) { this.logger.log( level, new UncheckedText( new FormattedText( "Written %d byte(s) to %s in %dms.", this.bytes.get(), this.destination, this.time.get() ) ).asString() ); } }
Example 2
Source File: ConsoleHandler.java From buck with Apache License 2.0 | 6 votes |
private boolean isLoggableWithRegisteredLogLevel(LogRecord record) { long recordThreadId = record.getThreadID(); String logRecordCommandId = state.threadIdToCommandId(recordThreadId); if (logRecordCommandId == null) { // An unregistered thread created this LogRecord, so we don't want to force logging it. return false; } Level commandIdLogLevel = state.getLogLevel(logRecordCommandId); if (commandIdLogLevel == null) { // No log level override registered for this command ID. Don't force logging it. return false; } // Level.ALL.intValue() is Integer.MIN_VALUE, so have to compare it explicitly. return commandIdLogLevel.equals(Level.ALL) || commandIdLogLevel.intValue() >= record.getLevel().intValue(); }
Example 3
Source File: CougarException.java From cougar with Apache License 2.0 | 6 votes |
private void logMe(ServerFaultCode serverFault, Level level) { // If it's an internal error, then we should always log. // A client fault is only logged if we're on debug logging. if (ResponseCode.InternalError == serverFault.getResponseCode()) { level = Level.WARNING; } Logger logger = getLogger(); String additionalInfo = additionalInfo(); String message = additionalInfo == null ? "Exception thrown" : "Exception thrown: " + additionalInfo; if (level.equals(Level.SEVERE)) { logger.error(message, this); } else if (level.equals(Level.WARNING)) { logger.warn(message, this); } else { logger.debug(message, this); } }
Example 4
Source File: TaskLogger.java From birt with Eclipse Public License 1.0 | 6 votes |
protected int getMessageLevel( LogRecord record ) { Level level = record.getLevel( ); if ( level.equals( Level.SEVERE ) ) { return Project.MSG_ERR; } if ( level.equals( Level.WARNING ) ) { return Project.MSG_WARN; } if ( level.equals( Level.INFO ) ) { return Project.MSG_INFO; } return Project.MSG_VERBOSE; }
Example 5
Source File: ConsoleUtils.java From buck with Apache License 2.0 | 6 votes |
/** Formats a {@link ConsoleEvent} and adds it to {@code lines}. */ public static ImmutableList<String> formatConsoleEvent(ConsoleEvent consoleEvent, Ansi ansi) { String message = consoleEvent.getMessage(); if (message == null) { LOG.error("Formatting console event with null message"); return ImmutableList.of(); } String formattedLine = ""; Level logEventLevel = consoleEvent.getLevel(); if (consoleEvent.containsAnsiEscapeCodes() || logEventLevel.equals(Level.INFO)) { formattedLine = message; } else { if (logEventLevel.equals(Level.WARNING)) { formattedLine = ansi.asWarningText(message); } else if (logEventLevel.equals(Level.SEVERE)) { formattedLine = ansi.asHighlightedFailureText(message); } } if (formattedLine.isEmpty()) { return ImmutableList.of(); } return ImmutableList.copyOf(Splitter.on(System.lineSeparator()).split(formattedLine)); }
Example 6
Source File: ExpectedLogs.java From beam with Apache License 2.0 | 6 votes |
private TypeSafeMatcher<LogRecord> matcher( final Level level, final String substring, final Throwable throwable) { return new TypeSafeMatcher<LogRecord>() { @Override public void describeTo(Description description) { description.appendText( String.format( "log message of level [%s] containg message [%s] with exception [%s] " + "containing message [%s]", level, substring, throwable.getClass(), throwable.getMessage())); } @Override protected boolean matchesSafely(LogRecord item) { return level.equals(item.getLevel()) && item.getMessage().contains(substring) && item.getThrown().getClass().equals(throwable.getClass()) && item.getThrown().getMessage().contains(throwable.getMessage()); } }; }
Example 7
Source File: ProtobufSerialization.java From vespa with Apache License 2.0 | 6 votes |
private static LogProtocol.LogMessage.Level toLogMessageLevel(Level level) { Level vespaLevel = LogLevel.getVespaLogLevel(level); if (vespaLevel.equals(LogLevel.FATAL)) { return LogProtocol.LogMessage.Level.FATAL; } else if (vespaLevel.equals(LogLevel.ERROR)) { return LogProtocol.LogMessage.Level.ERROR; } else if (vespaLevel.equals(LogLevel.WARNING)) { return LogProtocol.LogMessage.Level.WARNING; } else if (vespaLevel.equals(LogLevel.CONFIG)) { return LogProtocol.LogMessage.Level.CONFIG; } else if (vespaLevel.equals(LogLevel.INFO)) { return LogProtocol.LogMessage.Level.INFO; } else if (vespaLevel.equals(LogLevel.EVENT)) { return LogProtocol.LogMessage.Level.EVENT; } else if (vespaLevel.equals(LogLevel.DEBUG)) { return LogProtocol.LogMessage.Level.DEBUG; } else if (vespaLevel.equals(LogLevel.SPAM)) { return LogProtocol.LogMessage.Level.SPAM; } else { return LogProtocol.LogMessage.Level.UNKNOWN; } }
Example 8
Source File: ExpectedLogs.java From beam with Apache License 2.0 | 5 votes |
private TypeSafeMatcher<LogRecord> matcher(final Level level, final String substring) { return new TypeSafeMatcher<LogRecord>() { @Override public void describeTo(Description description) { description.appendText( String.format("log message of level [%s] containing message [%s]", level, substring)); } @Override protected boolean matchesSafely(LogRecord item) { return level.equals(item.getLevel()) && item.getMessage().contains(substring); } }; }
Example 9
Source File: LogMessageAccumulator.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public LogRecord findRecord(Level level, String message) { synchronized (records) { for (LogRecord r : records) { if (level.equals(r.getLevel()) && message.equals(r.getMessage())) return r; } return null; } }
Example 10
Source File: LogMessageAccumulator.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public LogRecord findRecord(Level level, String message) { synchronized (records) { for (LogRecord r : records) { if (level.equals(r.getLevel()) && message.equals(r.getMessage())) return r; } return null; } }
Example 11
Source File: LogViewer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public LogLevelMenu() { super("log_level"); for (final Level level : LogViewer.SELECTABLE_LEVELS) { JMenuItem item = new JMenuItem(new LoggedAbstractAction(level.getName()) { private static final long serialVersionUID = 1L; @Override public void loggedActionPerformed(ActionEvent e) { new Thread(new Runnable() { @Override public void run() { // change the log level outside the EDT // no progress thread because the part that may take some time (the // GUI refresh by Swing) cannot be cancelled anyway setLogLevel(level); } }).start(); } }); // highlight current log level if (getLogSelectionModel().getCurrentLogModel() != null) { if (level.equals(getLogSelectionModel().getCurrentLogModel().getLogLevel())) { item.setFont(item.getFont().deriveFont(Font.BOLD)); } } add(item); } }
Example 12
Source File: DebugLoggerConfigurator.java From bazel with Apache License 2.0 | 5 votes |
/** Configures "com.google.devtools.build.*" loggers to the given {@code level}. */ public static void setupLogging(Level level) { if (!level.equals(currentVerbosityLevel)) { templateLogger.setLevel(level); templateLogger.info("Log level: " + templateLogger.getLevel()); currentVerbosityLevel = level; } }
Example 13
Source File: CLRBufferedLogHandler.java From reef with Apache License 2.0 | 5 votes |
/** * Returns the integer value of the log record's level to be used * by the CLR Bridge log function. */ private int getLevel(final Level recordLevel) { if (recordLevel.equals(Level.OFF)) { return 0; } else if (recordLevel.equals(Level.SEVERE)) { return 1; } else if (recordLevel.equals(Level.WARNING)) { return 2; } else if (recordLevel.equals(Level.ALL)) { return 4; } else { return 3; } }
Example 14
Source File: LoggingOutputStream.java From cactoos with MIT License | 5 votes |
@Override public void flush() throws IOException { this.origin.flush(); final Level level = this.logger.getLevel(); if (level.equals(Level.INFO)) { this.logger.log( level, new UncheckedText( new FormattedText( "Written %d byte(s) to %s in %dms.", this.bytes.get(), this.destination, this.time.get() ) ).asString() ); } this.logger.log( level, new UncheckedText( new FormattedText( "Flushed output stream from %s.", this.destination ) ).asString() ); }
Example 15
Source File: LoggingOutputStream.java From cactoos with MIT License | 5 votes |
@Override public void close() throws IOException { this.origin.close(); final Level level = this.logger.getLevel(); if (level.equals(Level.INFO)) { this.logger.log( level, new UncheckedText( new FormattedText( "Written %d byte(s) to %s in %dms.", this.bytes.get(), this.destination, this.time.get() ) ).asString() ); } this.logger.log( level, new UncheckedText( new FormattedText( "Closed output stream from %s.", this.destination ) ).asString() ); }
Example 16
Source File: ComponentDemo.java From darklaf with MIT License | 5 votes |
default JMenu createDevSettings() { JMenu dev = new JMenu("Dev"); JMenu logging = new JMenu("Logging"); ButtonGroup bg = new ButtonGroup(); Level[] levels = new Level[]{Level.ALL, Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF}; Level currentLevel = LafManager.getLogLevel(); for (Level level : levels) { JRadioButtonMenuItem mi = new JRadioButtonMenuItem(level.getName()); mi.addActionListener(e -> LafManager.setLogLevel(level)); bg.add(mi); logging.add(mi); if (level.equals(currentLevel)) { mi.setSelected(true); } } JCheckBoxMenuItem aaPainting = new JCheckBoxMenuItem("Translucent Antialiasing"); aaPainting.addActionListener(e -> StringPainter.setTranslucentAAPaintingEnabled(aaPainting.isSelected())); aaPainting.setSelected(StringPainter.isTranslucentAAPaintingEnabled()); JCheckBoxMenuItem experimentalAA = new JCheckBoxMenuItem("Experimental Antialiasing"); experimentalAA.addActionListener(e -> StringPainter.setExperimentalAntialiasingEnabled(experimentalAA.isSelected())); experimentalAA.setSelected(StringPainter.isExperimentalAntialiasingEnabled()); dev.add(logging); dev.add(aaPainting); dev.add(experimentalAA); dev.add(new JCheckBoxMenuItem("Custom Decorations") { { setSelected(LafManager.isDecorationsEnabled()); addActionListener(e -> LafManager.setDecorationsEnabled(isSelected())); } }); return dev; }
Example 17
Source File: VespaLogHandlerTestCase.java From vespa with Apache License 2.0 | 4 votes |
@Override public boolean shouldLog(Level level) { return (level.equals(logLevel)); }
Example 18
Source File: ConsoleModel.java From triplea with GNU General Public License v3.0 | 4 votes |
static String fromLevel(final Level level) { return level.equals(DEBUG.level) ? DEBUG.label : NORMAL.label; }
Example 19
Source File: Loggers.java From sis with Apache License 2.0 | 4 votes |
/** * Returns a map of effective logging levels for SIS loggers. The effective logging level take in account the level * of parent loggers and the level of handlers. For example if a logger level is set to {@link Level#FINE} but no * handler have a level finer than {@link Level#INFO}, then the effective logging level will be {@link Level#INFO}. * * <p>This method does not report the loggers that have an effective level identical to its parent logger.</p> * * @return the effective logging levels of SIS loggers. */ public static SortedMap<String,Level> getEffectiveLevels() { final SortedMap<String,Level> levels = new TreeMap<>(); for (final Field field : Loggers.class.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) && field.getType() == String.class) try { levels.put((String) field.get(null), null); } catch (IllegalAccessException e) { /* * Should never happen, unless we added some fields and forgot to update this method. * In such case forget the problematic fields and search the next one. This is okay * since this method is only for information purpose. */ Logging.unexpectedException(Logging.getLogger(SYSTEM), Loggers.class, "getEffectiveLevels", e); } } /* * Process the loggers in alphabetical order. The intent is to process parent loggers before child. * The first logger in the map should be the SIS root logger, "org.apache.sis". */ final Iterator<Map.Entry<String,Level>> it = levels.entrySet().iterator(); while (it.hasNext()) { final Map.Entry<String,Level> entry = it.next(); final String name = entry.getKey(); final Logger logger = Logging.getLogger(name); Level level = getEffectiveLevel(logger); final Level h = getHandlerLevel(logger); if (h.intValue() > level.intValue()) { level = h; // Take in account the logging level of handlers. } entry.setValue(level); /* * Now verify if the level is identical to the effective level of parent logger. * If they are identical, then we remove the entry in order to report only the changes. */ Logger parent = logger; while ((parent = parent.getParent()) != null) { final Level p = levels.get(parent.getName()); if (p != null) { if (p.equals(level)) { it.remove(); } break; } } } return levels; }
Example 20
Source File: ProLogger.java From triplea with GNU General Public License v3.0 | 3 votes |
/** * Some notes on using the Pro AI logger: First, to make the logs easily readable even when there * are hundreds of lines, I want every considerable step down in the call stack to mean more log * message indentation. For example, the base logs in the {@link AbstractProAi} class have no * indentation before them, but the base logs in the {@link * games.strategy.triplea.ai.pro.ProCombatMoveAi} class will have two spaces inserted at the * start, and the level below that, four spaces. In this way, when you're reading the log, you can * skip over unimportant areas with speed because of the indentation. Second, I generally want the * Fine logs to be messages that run less than 10 times each round, including almost all messages * in the Pro AI class. Finest for messages showing details within a method that, for example, * returns a value. (So, for example, the NCM_Task method IsTaskWorthwhile() would primarily use * finest, as it just returns a boolean, and the logs within it are just for details) Finer for * just about everything else. (There's also the SERVER, INFO, etc. levels) Just keep these things * in mind while adding new logging code. */ public static void log(final Level level, final String message, final @Nullable Throwable t) { final ProLogSettings settings = ProLogSettings.loadSettings(); if (!settings.isLogEnabled()) { return; // Skip displaying to settings window if settings window option is turned off } final Level logDepth = settings.getLogLevel(); if (logDepth.equals(Level.FINE) && (level.equals(Level.FINER) || level.equals(Level.FINEST))) { return; // If the settings window log depth is a higher level than this messages, skip } if (logDepth.equals(Level.FINER) && level.equals(Level.FINEST)) { return; } ProLogUi.notifyAiLogMessage(formatMessage(message, t, level)); }