org.springframework.shell.support.logging.HandlerUtils Java Examples
The following examples show how to use
org.springframework.shell.support.logging.HandlerUtils.
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: LensInterpreter.java From zeppelin with Apache License 2.0 | 6 votes |
private InterpreterResult handleHelp(JLineShell shell, String st) { java.util.logging.StreamHandler sh = null; java.util.logging.Logger springLogger = null; java.util.logging.Formatter formatter = new java.util.logging.Formatter() { public String format(java.util.logging.LogRecord record) { return record.getMessage(); } }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { sh = new java.util.logging.StreamHandler(baos, formatter); springLogger = HandlerUtils.getLogger(org.springframework.shell.core.SimpleParser.class); springLogger.addHandler(sh); shell.executeCommand(st); } catch (Exception e) { LOGGER.error(e.getMessage(), e); return new InterpreterResult(Code.ERROR, e.getMessage()); } finally { sh.flush(); springLogger.removeHandler(sh); sh.close(); } return new InterpreterResult(Code.SUCCESS, baos.toString()); }
Example #2
Source File: Application.java From spring-data-dev-tools with Apache License 2.0 | 5 votes |
public static void main(String[] args) { SpringApplication application = new SpringApplication(Application.class); application.setAdditionalProfiles("local"); try { BootShim bs = new BootShim(args, application.run(args)); bs.run(); } catch (RuntimeException e) { throw e; } finally { HandlerUtils.flushAllHandlers(Logger.getLogger("")); } }
Example #3
Source File: ShellCommandLineRunner.java From spring-cloud-dashboard with Apache License 2.0 | 4 votes |
private ExitShellRequest doRun() { this.stopWatch.start(); try { String[] commandsToExecuteAndThenQuit = this.commandLine.getShellCommandsToExecute(); ExitShellRequest exitShellRequest; if (null != commandsToExecuteAndThenQuit) { boolean successful = false; exitShellRequest = ExitShellRequest.FATAL_EXIT; for (String cmd : commandsToExecuteAndThenQuit) { if (!(successful = this.lineShellComponent.executeCommand(cmd).isSuccess())) break; } if (successful) { exitShellRequest = ExitShellRequest.NORMAL_EXIT; } } else if (this.applicationArguments.containsOption("help")) { System.out.println(FileUtils.readBanner(ShellCommandLineRunner.class, "/usage.txt")); exitShellRequest = ExitShellRequest.NORMAL_EXIT; } else { this.lineShellComponent.start(); this.lineShellComponent.promptLoop(); exitShellRequest = this.lineShellComponent.getExitShellRequest(); if (exitShellRequest == null) { exitShellRequest = ExitShellRequest.NORMAL_EXIT; } this.lineShellComponent.waitForComplete(); } if (this.lineShellComponent.isDevelopmentMode()) { System.out.println("Total execution time: " + this.stopWatch .getLastTaskTimeMillis() + " ms"); } return exitShellRequest; } catch (Exception ex) { throw new ShellException(ex.getMessage(), ex); } finally { HandlerUtils.flushAllHandlers(this.logger); this.stopWatch.stop(); } }
Example #4
Source File: ShellCommandLineRunner.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private ExitShellRequest doRun() { this.stopWatch.start(); try { String[] commandsToExecuteAndThenQuit = this.commandLine.getShellCommandsToExecute(); ExitShellRequest exitShellRequest; if (null != commandsToExecuteAndThenQuit) { boolean successful = false; exitShellRequest = ExitShellRequest.FATAL_EXIT; for (String cmd : commandsToExecuteAndThenQuit) { if (!(successful = this.lineShellComponent.executeCommand(cmd).isSuccess())) break; } if (successful) { exitShellRequest = ExitShellRequest.NORMAL_EXIT; } } else if (this.applicationArguments.containsOption("help")) { System.out.println(FileUtils.readBanner(ShellCommandLineRunner.class, "/usage.txt")); exitShellRequest = ExitShellRequest.NORMAL_EXIT; } else { this.lineShellComponent.start(); this.lineShellComponent.promptLoop(); exitShellRequest = this.lineShellComponent.getExitShellRequest(); if (exitShellRequest == null) { exitShellRequest = ExitShellRequest.NORMAL_EXIT; } this.lineShellComponent.waitForComplete(); } if (this.lineShellComponent.isDevelopmentMode()) { System.out.println("Total execution time: " + this.stopWatch.getLastTaskTimeMillis() + " ms"); } return exitShellRequest; } catch (Exception ex) { throw new ShellException(ex.getMessage(), ex); } finally { HandlerUtils.flushAllHandlers(this.logger); this.stopWatch.stop(); } }