TraceListener.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
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 org.qedeq.base.trace.Trace;
19 
20 /**
21  * Listener that writes events to the trace.
22  *
23  @author  Michael Meyling
24  */
25 public final class TraceListener implements LogListener {
26 
27     /** Last modules URL .*/
28     private String lastModuleUrl = "";
29 
30     /**
31      * Constructor.
32      */
33     public TraceListener() {
34     }
35 
36     public final void logMessageState(final String text, final String url) {
37         if (!lastModuleUrl.equals(url)) {
38             Trace.log(url);
39             lastModuleUrl = (url != null ? url : "");
40         }
41         Trace.log(" state:   " + text);
42     }
43 
44     public final void logFailureState(final String text, final String url,
45             final String description) {
46         if (!lastModuleUrl.equals(url)) {
47             Trace.log(url);
48             lastModuleUrl = (url != null ? url : "");
49         }
50         Trace.log(" failure: " + text, description);
51     }
52 
53     public final void logSuccessfulState(final String text, final String url) {
54         if (!lastModuleUrl.equals(url)) {
55             Trace.log(url);
56             lastModuleUrl = (url != null ? url : "");
57         }
58         Trace.log(" success: " + text);
59     }
60 
61     public void logRequest(final String text, final String url) {
62         if (!lastModuleUrl.equals(url)) {
63             Trace.log(url);
64             lastModuleUrl = (url != null ? url : "");
65         }
66         Trace.log(" request: " + text);
67     }
68 
69     public final void logMessage(final String text) {
70         Trace.log(text);
71     }
72 
73     public void logSuccessfulReply(final String text, final String url) {
74         if (!lastModuleUrl.equals(url)) {
75             Trace.log(url);
76             lastModuleUrl = (url != null ? url : "");
77         }
78         Trace.log(" reply:   " + text);
79     }
80 
81     public void logFailureReply(final String text, final String url, final String description) {
82         if (!lastModuleUrl.equals(url)) {
83             Trace.log(url);
84             lastModuleUrl = (url != null ? url : "");
85         }
86         Trace.log(" reply:   " + text, description);
87     }
88 
89 }