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

ConsoleEventListenerForTests.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* $Id$ */
  18. package org.apache.fop.util;
  19. import org.apache.fop.events.Event;
  20. import org.apache.fop.events.EventFormatter;
  21. import org.apache.fop.events.EventListener;
  22. import org.apache.fop.events.model.EventSeverity;
  23. /** A simple event listener that writes the events to stdout and sterr. */
  24. public class ConsoleEventListenerForTests implements EventListener {
  25. private String name;
  26. private EventSeverity logLevel;
  27. /**
  28. * Creates a new event listener with console output on severity INFO. This object will
  29. * write out the name of the test before the first log message.
  30. * @param name the name of the test
  31. */
  32. public ConsoleEventListenerForTests(String name) {
  33. this(name, EventSeverity.INFO);
  34. }
  35. /**
  36. * Creates a new event listener with console output. This object will
  37. * write out the name of the test before the first log message.
  38. * @param name the name of the test
  39. * @param logLevel the logging level
  40. */
  41. public ConsoleEventListenerForTests(String name, EventSeverity logLevel) {
  42. this.name = name;
  43. this.logLevel = logLevel;
  44. }
  45. /** {@inheritDoc} */
  46. public void processEvent(Event event) {
  47. EventSeverity severity = event.getSeverity();
  48. if (severity == EventSeverity.FATAL) {
  49. log("FATAL", event);
  50. return;
  51. }
  52. if (logLevel == EventSeverity.FATAL) {
  53. return;
  54. }
  55. if (severity == EventSeverity.ERROR) {
  56. log("ERROR", event);
  57. return;
  58. }
  59. if (logLevel == EventSeverity.ERROR) {
  60. return;
  61. }
  62. if (severity == EventSeverity.WARN) {
  63. log("WARN ", event);
  64. }
  65. if (logLevel == EventSeverity.WARN) {
  66. return;
  67. }
  68. if (severity == EventSeverity.INFO) {
  69. log("INFO ", event);
  70. }
  71. }
  72. private void log(String levelString, Event event) {
  73. if (this.name != null) {
  74. System.out.println("Test: " + this.name);
  75. this.name = null;
  76. }
  77. String msg = EventFormatter.format(event);
  78. System.out.println(" [" + levelString + "] " + msg);
  79. }
  80. }