LogWriter.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * $Id: LogWriter.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/system/io/Writer.php';
  22. require_once 'phing/Task.php';
  23. /**
  24. * Extends the Writer class to output messages to Phing's log
  25. *
  26. * @author Michiel Rook <michiel.rook@gmail.com>
  27. * @version $Id: LogWriter.php 905 2010-10-05 16:28:03Z mrook $
  28. * @package phing.util
  29. */
  30. class LogWriter extends Writer
  31. {
  32. private $task = NULL;
  33. private $level = NULL;
  34. /**
  35. * Constructs a new LogWriter object
  36. */
  37. function __construct(Task $task, $level = Project::MSG_INFO)
  38. {
  39. $this->task = $task;
  40. $this->level = $level;
  41. }
  42. /**
  43. * @see Writer::write()
  44. */
  45. function write($buf, $off = null, $len = null)
  46. {
  47. $lines = explode("\n", $buf);
  48. foreach ($lines as $line)
  49. {
  50. if ($line == "")
  51. {
  52. continue;
  53. }
  54. $this->task->log($line, $this->level);
  55. }
  56. }
  57. /**
  58. * @see Writer::reset()
  59. */
  60. function reset()
  61. {
  62. }
  63. /**
  64. * @see Writer::close()
  65. */
  66. function close()
  67. {
  68. }
  69. /**
  70. * @see Writer::open()
  71. */
  72. function open()
  73. {
  74. }
  75. /**
  76. * @see Writer::getResource()
  77. */
  78. function getResource()
  79. {
  80. return $this->task;
  81. }
  82. }