@Test public void testNullMessage() { assertEquals("@|RED ClientException|@", logger.getFormattedMessage(new ClientException(null))); assertEquals("@|RED outer|@", logger.getFormattedMessage(new ClientException("outer", new NullPointerException(null)))); }
@Nonnull public String getFormattedMessage(@Nonnull final Throwable e) { AnsiFormattedText msg = AnsiFormattedText.s().colorRed(); if (isDebugEnabled()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); msg.append(new String(baos.toByteArray(), StandardCharsets.UTF_8)); } else { if (e instanceof AnsiFormattedException) { msg = msg.append(((AnsiFormattedException) e).getFormattedMessage()); } else if (e instanceof ClientException && e.getMessage() != null && e.getMessage().contains("Missing username")) { msg = msg.append(e.getMessage()) .append("\nPlease specify --username, and optionally --password, as argument(s)") .append("\nor as environment variable(s), NEO4J_USERNAME, and NEO4J_PASSWORD respectively.") .append("\nSee --help for more info."); } else { Throwable cause = e; if (e instanceof ServiceUnavailableException) { Throwable[] suppressed = e.getSuppressed(); for (Throwable s : suppressed) { if (s instanceof DiscoveryException ) { cause = getRootCause(s); break; } } } if (cause.getMessage() != null) { msg = msg.append(cause.getMessage()); } else { msg = msg.append(cause.getClass().getSimpleName()); } } } return msg.formattedString(); }
AnsiLogger implements Logger { @Nonnull public String getFormattedMessage(@Nonnull final Throwable e) { AnsiFormattedText msg = AnsiFormattedText.s().colorRed(); if (isDebugEnabled()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); msg.append(new String(baos.toByteArray(), StandardCharsets.UTF_8)); } else { if (e instanceof AnsiFormattedException) { msg = msg.append(((AnsiFormattedException) e).getFormattedMessage()); } else if (e instanceof ClientException && e.getMessage() != null && e.getMessage().contains("Missing username")) { msg = msg.append(e.getMessage()) .append("\nPlease specify --username, and optionally --password, as argument(s)") .append("\nor as environment variable(s), NEO4J_USERNAME, and NEO4J_PASSWORD respectively.") .append("\nSee --help for more info."); } else { Throwable cause = e; if (e instanceof ServiceUnavailableException) { Throwable[] suppressed = e.getSuppressed(); for (Throwable s : suppressed) { if (s instanceof DiscoveryException ) { cause = getRootCause(s); break; } } } if (cause.getMessage() != null) { msg = msg.append(cause.getMessage()); } else { msg = msg.append(cause.getClass().getSimpleName()); } } } return msg.formattedString(); } }
AnsiLogger implements Logger { @Nonnull public String getFormattedMessage(@Nonnull final Throwable e) { AnsiFormattedText msg = AnsiFormattedText.s().colorRed(); if (isDebugEnabled()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); msg.append(new String(baos.toByteArray(), StandardCharsets.UTF_8)); } else { if (e instanceof AnsiFormattedException) { msg = msg.append(((AnsiFormattedException) e).getFormattedMessage()); } else if (e instanceof ClientException && e.getMessage() != null && e.getMessage().contains("Missing username")) { msg = msg.append(e.getMessage()) .append("\nPlease specify --username, and optionally --password, as argument(s)") .append("\nor as environment variable(s), NEO4J_USERNAME, and NEO4J_PASSWORD respectively.") .append("\nSee --help for more info."); } else { Throwable cause = e; if (e instanceof ServiceUnavailableException) { Throwable[] suppressed = e.getSuppressed(); for (Throwable s : suppressed) { if (s instanceof DiscoveryException ) { cause = getRootCause(s); break; } } } if (cause.getMessage() != null) { msg = msg.append(cause.getMessage()); } else { msg = msg.append(cause.getClass().getSimpleName()); } } } return msg.formattedString(); } AnsiLogger(final boolean debug);  AnsiLogger(final boolean debug, @Nonnull Format format,
                      @Nonnull PrintStream out, @Nonnull PrintStream err); }
AnsiLogger implements Logger { @Nonnull public String getFormattedMessage(@Nonnull final Throwable e) { AnsiFormattedText msg = AnsiFormattedText.s().colorRed(); if (isDebugEnabled()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); msg.append(new String(baos.toByteArray(), StandardCharsets.UTF_8)); } else { if (e instanceof AnsiFormattedException) { msg = msg.append(((AnsiFormattedException) e).getFormattedMessage()); } else if (e instanceof ClientException && e.getMessage() != null && e.getMessage().contains("Missing username")) { msg = msg.append(e.getMessage()) .append("\nPlease specify --username, and optionally --password, as argument(s)") .append("\nor as environment variable(s), NEO4J_USERNAME, and NEO4J_PASSWORD respectively.") .append("\nSee --help for more info."); } else { Throwable cause = e; if (e instanceof ServiceUnavailableException) { Throwable[] suppressed = e.getSuppressed(); for (Throwable s : suppressed) { if (s instanceof DiscoveryException ) { cause = getRootCause(s); break; } } } if (cause.getMessage() != null) { msg = msg.append(cause.getMessage()); } else { msg = msg.append(cause.getClass().getSimpleName()); } } } return msg.formattedString(); } AnsiLogger(final boolean debug);  AnsiLogger(final boolean debug, @Nonnull Format format,
                      @Nonnull PrintStream out, @Nonnull PrintStream err); @Nonnull @Override PrintStream getOutputStream(); @Nonnull @Override PrintStream getErrorStream(); @Nonnull @Override Format getFormat(); @Override void setFormat(@Nonnull Format format); @Override boolean isDebugEnabled(); @Override void printError(@Nonnull Throwable throwable); @Override void printError(@Nonnull String s); @Override void printOut(@Nonnull final String msg); @Nonnull String getFormattedMessage(@Nonnull final Throwable e); }
AnsiLogger implements Logger { @Nonnull public String getFormattedMessage(@Nonnull final Throwable e) { AnsiFormattedText msg = AnsiFormattedText.s().colorRed(); if (isDebugEnabled()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); e.printStackTrace(ps); msg.append(new String(baos.toByteArray(), StandardCharsets.UTF_8)); } else { if (e instanceof AnsiFormattedException) { msg = msg.append(((AnsiFormattedException) e).getFormattedMessage()); } else if (e instanceof ClientException && e.getMessage() != null && e.getMessage().contains("Missing username")) { msg = msg.append(e.getMessage()) .append("\nPlease specify --username, and optionally --password, as argument(s)") .append("\nor as environment variable(s), NEO4J_USERNAME, and NEO4J_PASSWORD respectively.") .append("\nSee --help for more info."); } else { Throwable cause = e; if (e instanceof ServiceUnavailableException) { Throwable[] suppressed = e.getSuppressed(); for (Throwable s : suppressed) { if (s instanceof DiscoveryException ) { cause = getRootCause(s); break; } } } if (cause.getMessage() != null) { msg = msg.append(cause.getMessage()); } else { msg = msg.append(cause.getClass().getSimpleName()); } } } return msg.formattedString(); } AnsiLogger(final boolean debug);  AnsiLogger(final boolean debug, @Nonnull Format format,
                      @Nonnull PrintStream out, @Nonnull PrintStream err); @Nonnull @Override PrintStream getOutputStream(); @Nonnull @Override PrintStream getErrorStream(); @Nonnull @Override Format getFormat(); @Override void setFormat(@Nonnull Format format); @Override boolean isDebugEnabled(); @Override void printError(@Nonnull Throwable throwable); @Override void printError(@Nonnull String s); @Override void printOut(@Nonnull final String msg); @Nonnull String getFormattedMessage(@Nonnull final Throwable e);  }