You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogStreamHandler.java 2.3 kB

11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.taskdefs;
  19. import java.io.IOException;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.ProjectComponent;
  22. import org.apache.tools.ant.Task;
  23. /**
  24. * Logs standard output and error of a subprocess to the log system of ant.
  25. *
  26. * @since Ant 1.2
  27. */
  28. public class LogStreamHandler extends PumpStreamHandler {
  29. /**
  30. * Creates log stream handler
  31. *
  32. * @param task the task for whom to log
  33. * @param outlevel the loglevel used to log standard output
  34. * @param errlevel the loglevel used to log standard error
  35. */
  36. public LogStreamHandler(Task task, int outlevel, int errlevel) {
  37. this((ProjectComponent) task, outlevel, errlevel);
  38. }
  39. /**
  40. * Creates log stream handler
  41. *
  42. * @param pc the project component for whom to log
  43. * @param outlevel the loglevel used to log standard output
  44. * @param errlevel the loglevel used to log standard error
  45. */
  46. public LogStreamHandler(ProjectComponent pc, int outlevel, int errlevel) {
  47. super(new LogOutputStream(pc, outlevel),
  48. new LogOutputStream(pc, errlevel));
  49. }
  50. /**
  51. * Stop the log stream handler.
  52. */
  53. public void stop() {
  54. super.stop();
  55. try {
  56. getErr().close();
  57. getOut().close();
  58. } catch (IOException e) {
  59. // plain impossible
  60. throw new BuildException(e);
  61. }
  62. }
  63. }