diff --git a/common/src/java/org/apache/hive/common/util/StreamPrinter.java b/common/src/java/org/apache/hive/common/util/StreamPrinter.java index 72638fdb966a63c64e44f2d952ecc49b4b0b5121..1517751347490a9e3ed4b11c2981cfed24745102 100644 --- a/common/src/java/org/apache/hive/common/util/StreamPrinter.java +++ b/common/src/java/org/apache/hive/common/util/StreamPrinter.java @@ -33,12 +33,12 @@ public class StreamPrinter extends Thread { InputStream is; String type; - PrintStream os; + PrintStream[] outputStreams; - public StreamPrinter(InputStream is, String type, PrintStream os) { + public StreamPrinter(InputStream is, String type, PrintStream... outputStreams) { this.is = is; this.type = type; - this.os = os; + this.outputStreams = outputStreams; } @Override @@ -50,18 +50,22 @@ public void run() { String line = null; if (type != null) { while ((line = br.readLine()) != null) { - os.println(type + ">" + line); + for (PrintStream os: outputStreams) { + os.println(type + ">" + line); + } } } else { while ((line = br.readLine()) != null) { - os.println(line); + for (PrintStream os: outputStreams) { + os.println(line); + } } } br.close(); - br=null; + br = null; } catch (IOException ioe) { ioe.printStackTrace(); - }finally{ + } finally { IOUtils.closeStream(br); } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/TaskRunner.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/TaskRunner.java index f6fd08104f6d5a8c93bca1f5d77468096e823144..81f6db0ed494fa8dcd78afed5c604cb080234017 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/TaskRunner.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/TaskRunner.java @@ -32,7 +32,6 @@ **/ public class TaskRunner extends Thread { - protected Task tsk; protected TaskResult result; protected SessionState ss; @@ -103,7 +102,7 @@ public void runSequential() { if (tsk.getException() == null) { tsk.setException(t); } - t.printStackTrace(); + LOG.error("Error in executeTask", t); } result.setExitVal(exitVal, tsk.getException()); } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapRedTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapRedTask.java index 310356c526149088b2c1fc5dc4c1da3cbf166595..a42c2e99fe62aac96c21e4c5590c1891c1ea529c 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapRedTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapRedTask.java @@ -301,8 +301,7 @@ public int execute(DriverContext driverContext) { return exitVal; } catch (Exception e) { - e.printStackTrace(); - LOG.error("Exception: " + e.getMessage()); + LOG.error("Got exception", e); return (1); } finally { try { @@ -313,7 +312,7 @@ public int execute(DriverContext driverContext) { } } catch (Exception e) { - LOG.error("Exception: " + e.getMessage()); + LOG.error("Exception: ", e); } } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java index f5500a4c4ece56fcd756c9c2159169228e542a6e..c81b14c660015ddb247cea578dc8bddd53f2c838 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java @@ -65,6 +65,7 @@ import org.apache.hadoop.hive.ql.plan.MapredLocalWork; import org.apache.hadoop.hive.ql.plan.OperatorDesc; import org.apache.hadoop.hive.ql.plan.api.StageType; +import org.apache.hadoop.hive.ql.session.OperationLog; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.ql.session.SessionState.LogHelper; import org.apache.hadoop.hive.serde2.ColumnProjectionUtils; @@ -317,8 +318,10 @@ public int executeInChildVM(DriverContext driverContext) { CachingPrintStream errPrintStream = new CachingPrintStream(System.err); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, errPrintStream); + StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out, + OperationLog.getCurrentOperationLog().getPrintStream()); + StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, errPrintStream, + OperationLog.getCurrentOperationLog().getPrintStream()); outPrinter.start(); errPrinter.start(); @@ -340,7 +343,7 @@ public int executeInChildVM(DriverContext driverContext) { return exitVal; } catch (Exception e) { - LOG.error("Exception: " + e, e); + LOG.error("Exception: ", e); return (1); } finally { if (secureDoAs != null) { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/session/OperationLog.java b/ql/src/java/org/apache/hadoop/hive/ql/session/OperationLog.java index 2ecdde9799683cd104323af170d8905fb3005b9e..6d0f14a6418caefaacc0326fc0a946178af673d8 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/session/OperationLog.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/session/OperationLog.java @@ -39,7 +39,11 @@ private final LogFile logFile; private LoggingLevel opLoggingLevel = LoggingLevel.UNKNOWN; - public static enum LoggingLevel { + public PrintStream getPrintStream() { + return logFile.getPrintStream(); + } + + public enum LoggingLevel { NONE, EXECUTION, PERFORMANCE, VERBOSE, UNKNOWN } @@ -221,5 +225,9 @@ private void resetIn() { } return logs; } + + public PrintStream getPrintStream() { + return out; + } } }