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 public Void processStdErr(InputStream stdErrInputStream)
031 throws ProcessException {
032
033 _processOut(true, stdErrInputStream);
034
035 return null;
036 }
037
038 public Void processStdOut(InputStream stdOutInputStream)
039 throws ProcessException {
040
041 _processOut(false, stdOutInputStream);
042
043 return null;
044 }
045
046 private void _processOut(boolean stdErr, InputStream inputStream)
047 throws ProcessException {
048
049 UnsyncBufferedReader unsyncBufferedReader =
050 new UnsyncBufferedReader(new InputStreamReader(inputStream));
051
052 String line = null;
053
054 try {
055 while ((line = unsyncBufferedReader.readLine()) != null) {
056 if (stdErr && _log.isErrorEnabled()) {
057 _log.error(line);
058 }
059 else if (!stdErr && _log.isInfoEnabled()) {
060 _log.info(line);
061 }
062 }
063 }
064 catch (IOException ioe) {
065 throw new ProcessException(ioe);
066 }
067 finally {
068 try {
069 unsyncBufferedReader.close();
070 }
071 catch (IOException ioe) {
072 throw new ProcessException(ioe);
073 }
074 }
075 }
076
077 private static Log _log = LogFactoryUtil.getLog(
078 LoggingOutputProcessor.class);
079
080 }