001
014
015 package com.liferay.portal.kernel.process;
016
017 import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020
021 import java.io.IOException;
022 import java.io.InputStream;
023 import java.io.InputStreamReader;
024
025
028 public class LoggingOutputProcessor implements OutputProcessor<Void, Void> {
029
030 @Override
031 public Void processStdErr(InputStream stdErrInputStream)
032 throws ProcessException {
033
034 _processOut(true, stdErrInputStream);
035
036 return null;
037 }
038
039 @Override
040 public Void processStdOut(InputStream stdOutInputStream)
041 throws ProcessException {
042
043 _processOut(false, stdOutInputStream);
044
045 return null;
046 }
047
048 private void _processOut(boolean stdErr, InputStream inputStream)
049 throws ProcessException {
050
051 UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
052 new InputStreamReader(inputStream));
053
054 String line = null;
055
056 try {
057 while ((line = unsyncBufferedReader.readLine()) != null) {
058 if (stdErr && _log.isErrorEnabled()) {
059 _log.error(line);
060 }
061 else if (!stdErr && _log.isInfoEnabled()) {
062 _log.info(line);
063 }
064 }
065 }
066 catch (IOException ioe) {
067 throw new ProcessException(ioe);
068 }
069 finally {
070 try {
071 unsyncBufferedReader.close();
072 }
073 catch (IOException ioe) {
074 throw new ProcessException(ioe);
075 }
076 }
077 }
078
079 private static Log _log = LogFactoryUtil.getLog(
080 LoggingOutputProcessor.class);
081
082 }