View Javadoc

1   /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">http://www.qedeq.org
2    *
3    * Copyright 2000-2014,  Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU General Public License for more details.
14   */
15  
16  package org.qedeq.kernel.bo.log;
17  
18  import java.io.PrintStream;
19  
20  import org.qedeq.base.utility.DateUtility;
21  
22  /**
23   * Listener that writes events to a stream.
24   *
25   * @author  Michael Meyling
26   */
27  public final class LogListenerImpl implements LogListener {
28  
29      /** Stream for output. */
30      private PrintStream out = System.out;
31  
32      /** For this module we logged the last event. */
33      private String lastModuleUrl = "";
34  
35      /**
36       * Constructor.
37       */
38      public LogListenerImpl() {
39          this(System.out);
40      }
41  
42      /**
43       * Constructor.
44       *
45       * @param   stream  Print to this stream.
46       */
47      public LogListenerImpl(final PrintStream stream) {
48          this.out = stream;
49      }
50  
51      /**
52       * Set output stream.
53       *
54       * @param   stream  Output stream.
55       */
56      public final void setPrintStream(final PrintStream stream) {
57          this.out = stream;
58      }
59  
60      public final void logMessageState(final String text, final String url) {
61          if (!lastModuleUrl.equals(url)) {
62              out.println(url);
63              lastModuleUrl = (url != null ? url : "");
64          }
65          out.println(DateUtility.getTimestamp() + " state:   " + text);
66      }
67  
68      public final void logFailureState(final String text, final String url,
69              final String description) {
70          if (!lastModuleUrl.equals(url)) {
71              out.println(url);
72              lastModuleUrl = (url != null ? url : "");
73          }
74          out.println(DateUtility.getTimestamp() + " failure: " + text + "\n\t"
75              + description);
76      }
77  
78      public final void logSuccessfulState(final String text, final String url) {
79          if (!lastModuleUrl.equals(url)) {
80              out.println(url);
81              lastModuleUrl = (url != null ? url : "");
82          }
83          out.println(DateUtility.getTimestamp() + " success: " + text);
84      }
85  
86      public void logRequest(final String text, final String url) {
87          if (!lastModuleUrl.equals(url)) {
88              out.println(url);
89              lastModuleUrl = (url != null ? url : "");
90          }
91          out.println(DateUtility.getTimestamp() + " request: " + text);
92      }
93  
94      public final void logMessage(final String text) {
95          lastModuleUrl = "";
96          out.println(DateUtility.getTimestamp() + " " + text);
97      }
98  
99  
100     public void logSuccessfulReply(final String text, final String url) {
101         if (!lastModuleUrl.equals(url)) {
102             out.println(url);
103             lastModuleUrl = (url != null ? url : "");
104         }
105         out.println(DateUtility.getTimestamp() + " reply:   " + text);
106     }
107 
108     public void logFailureReply(final String text, final String url, final String description) {
109         if (!lastModuleUrl.equals(url)) {
110             out.println(url);
111             lastModuleUrl = (url != null ? url : "");
112         }
113         out.println(DateUtility.getTimestamp() + " reply:   " + text + "\n\t" + description);
114     }
115 
116 }