private static synchronized void runTasks() { Log.debug("Running all shutdown-hook tasks"); // Iterate through copy of tasks list for (Task task : tasks.toArray(new Task[tasks.size()])) { Log.debug("Running task: ", task); try { task.run(); } catch (Throwable e) { Log.warn("Task failed", e); } } tasks.clear(); }
static void log(final Level level, final Supplier<String> message) { logr(level, () -> createRecord(level, message)); }
public static boolean isDebugEnabled() { return isEnabled(Level.FINE); }
@Override public void attach(LineReader reader) { if (this.reader != reader) { this.reader = reader; try { load(); } catch (IOException e) { Log.warn("Failed to load history", e); } } }
Log.warn("Attributes and size fields are ignored when creating a system terminal"); Log.debug("Error creating EXEC based terminal: ", e.getMessage(), e); exception.addSuppressed(e); return load(JnaSupport.class).winSysTerminal(name, type, ansiPassThrough, encoding, codepage, nativeSignals, signalHandler, paused); } catch (Throwable t) { Log.debug("Error creating JNA based terminal: ", t.getMessage(), t); exception.addSuppressed(t); return load(JansiSupport.class).winSysTerminal(name, type, ansiPassThrough, encoding, codepage, nativeSignals, signalHandler, paused); } catch (Throwable t) { Log.debug("Error creating JANSI based terminal: ", t.getMessage(), t); exception.addSuppressed(t); Log.debug("Error creating JNA based terminal: ", t.getMessage(), t); exception.addSuppressed(t); return new PosixSysTerminal(name, type, pty, encoding, nativeSignals, signalHandler); } catch (Throwable t) { Log.debug("Error creating JANSI based terminal: ", t.getMessage(), t); exception.addSuppressed(t); Log.debug("Error creating EXEC based terminal: ", t.getMessage(), t); exception.addSuppressed(t); if (Log.isDebugEnabled()) { Log.warn("Creating a dumb terminal", exception); } else {
Log.info("Error in tmux input loop", e);
public static Object register(String name, final Runnable handler, ClassLoader loader) { try { Class<?> signalHandlerClass = Class.forName("sun.misc.SignalHandler"); // Implement signal handler Object signalHandler = Proxy.newProxyInstance(loader, new Class<?>[]{signalHandlerClass}, (proxy, method, args) -> { // only method we are proxying is handle() if (method.getDeclaringClass() == Object.class) { if ("toString".equals(method.getName())) { return handler.toString(); } } else if (method.getDeclaringClass() == signalHandlerClass) { Log.trace(() -> "Calling handler " + toString(handler) + " for signal " + name); handler.run(); } return null; }); return doRegister(name, signalHandler); } catch (Exception e) { // Ignore this one too, if the above failed, the signal API is incompatible with what we're expecting Log.debug("Error registering handler for signal ", name, e); return null; } }
private static Thread addHook(final Thread thread) { Log.debug("Registering shutdown-hook: ", thread); Runtime.getRuntime().addShutdownHook(thread); return thread; }
public static void trace(final Object... messages) { log(Level.FINEST, messages); }
private static Object doRegister(String name, Object handler) throws Exception { Log.trace(() -> "Registering signal " + name + " with handler " + toString(handler)); if ("QUIT".equals(name) || "INFO".equals(name) && "9".equals(System.getProperty("java.specification.version"))) { Log.trace(() -> "Ignoring unsupported signal " + name); return null; } Class<?> signalClass = Class.forName("sun.misc.Signal"); Class<?> signalHandlerClass = Class.forName("sun.misc.SignalHandler"); Object signal = signalClass.getConstructor(String.class).newInstance(name); return signalClass.getMethod("handle", signalClass, signalHandlerClass) .invoke(null, signal, handler); }
static LogRecord createRecord(final Level level, final Object... messages) { Throwable cause = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); for (int i = 0; i < messages.length; i++) { // Special handling for the last message if its a throwable, render its stack on the next line if (i + 1 == messages.length && messages[i] instanceof Throwable) { cause = (Throwable) messages[i]; } else { render(ps, messages[i]); } } ps.close(); LogRecord r = new LogRecord(level, baos.toString()); r.setThrown(cause); return r; }
public LineReaderBuilder parser(Parser parser) { if (parser != null) { try { if (!Boolean.parseBoolean(LineReader.PROP_SUPPORT_PARSEDLINE) && !(parser.parse("", 0) instanceof CompletingParsedLine)) { Log.warn("The Parser of class " + parser.getClass().getName() + " does not support the CompletingParsedLine interface. " + "Completion with escaped or quoted words won't work correctly."); } } catch (Throwable t) { // Ignore } } this.parser = parser; return this; }
Log.info("Error in tmux input loop", e);
@Override public void load() throws IOException { Path path = getPath(); if (path != null) { try { if (Files.exists(path)) { Log.trace("Loading history from: ", path); try (BufferedReader reader = Files.newBufferedReader(path)) { internalClear(); reader.lines().forEach(line -> addHistoryLine(path, line)); lastLoaded = items.size(); nbEntriesInFile = lastLoaded; maybeResize(); } } } catch (IOException e) { Log.debug("Failed to load history; clearing", e); internalClear(); throw e; } } }
private static void removeHook(final Thread thread) { Log.debug("Removing shutdown-hook: ", thread); try { Runtime.getRuntime().removeShutdownHook(thread); } catch (IllegalStateException e) { // The VM is shutting down, not a big deal; ignore } }
public static void debug(Supplier<String> supplier) { log(Level.FINE, supplier); }
@Override public void purge() throws IOException { internalClear(); Path path = getPath(); if (path != null) { Log.trace("Purging history from: ", path); Files.deleteIfExists(path); } }
protected void pump() { try { while (!closing) { synchronized (lock) { if (paused) { pump = null; break; } } if (processConsoleInput()) { slaveInputPipe.flush(); } } } catch (IOException e) { if (!closing) { Log.warn("Error in WindowsStreamPump", e); try { close(); } catch (IOException e1) { Log.warn("Error closing terminal", e); } } } finally { synchronized (lock) { pump = null; } } }