Code example for Logger

Methods: Logger.log, finest, isLoggable, log

0
		return fullExecString;
	} 
    protected String executeCommand(String executionString, File tempOutputFile){
		String response = "";
		 
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Executing command line: "+executionString);
        } 
		ProcessBuilder pb = new ProcessBuilder("bash","-c",executionString);
		pb.redirectErrorStream(true);
		int shellExitStatus=0;
		try { 
			final Process shell = pb.start();
			 
			Callable<Integer> call = new Callable<Integer>(){
				public Integer call() throws Exception {
					shell.waitFor(); 
					return shell.exitValue(); 
				} 
			}; 
			ExecutorService service = Executors.newSingleThreadExecutor();
			try{ 
				Future<Integer> ft = service.submit(call);
				try{ 
					shellExitStatus = ft.get(getCommandTimeout(),TimeUnit.MILLISECONDS);
				} catch (TimeoutException ex) {
					shell.destroy(); 
					shellExitStatus=-5;
				} catch (ExecutionException e) {
					shell.destroy(); 
					shellExitStatus=-5;
				} 
				 
			} finally{ 
				service.shutdown();
			} 
			 
	        InputStream inStream = null;
	         
	        try { 
	        	inStream = org.apache.commons.io.FileUtils.openInputStream(tempOutputFile);
	        	response = IOUtils.toString(inStream);
	        }  
	        catch (IOException e) {
    			logger.log(Level.WARNING, "Error occured while reading command response.", e);
	        } 
	        finally { 
	            IOUtils.closeQuietly(inStream); 
	        } 
	         
		} 
		catch (IOException e) {
			logger.log(Level.WARNING, "Error occured while executing command. ExecStr: "+ executionString, e);
		} 
 
		catch (InterruptedException e) {
			logger.log(Level.WARNING, "Error occured while executing command. ExecStr: "+ executionString, e);
		} 
 
		if(shellExitStatus!=0){
			if(shellExitStatus==-5){
				logger.log(Level.WARNING, "Command exceeded timeout: "+shellExitStatus, executionString);
			} 
			else{ 
				logger.log(Level.WARNING, "Command returned status code: "+shellExitStatus, executionString);
			} 
		} 
		return response;
    } 
	private String convertStreamToStr(InputStream is) throws IOException {