01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.ajp.tomcat4;
18:
19: import org.apache.catalina.Logger;
20:
21: class Ajp13Logger {
22:
23: private String name = null;
24: private Ajp13Connector connector = null;
25: private boolean logStackTrace = false;
26:
27: Ajp13Logger() {
28: name = toString();
29: }
30:
31: void setConnector(Ajp13Connector connector) {
32: this .connector = connector;
33: }
34:
35: void setName(String name) {
36: this .name = name;
37: }
38:
39: /**
40: * Log a message on the Logger associated with our Container (if any)
41: *
42: * @param message Message to be logged
43: */
44: void log(String message) {
45:
46: if (logStackTrace) {
47: log(message, new Throwable());
48: } else {
49: Logger logger = getLogger();
50:
51: if (logger != null)
52: logger.log(name + " " + message);
53: else
54: System.out.println(name + " " + message);
55: }
56: }
57:
58: /**
59: * Log a message on the Logger associated with our Container (if any)
60: *
61: * @param message Message to be logged
62: * @param throwable Associated exception
63: */
64: void log(String message, Throwable throwable) {
65:
66: Logger logger = getLogger();
67:
68: if (logger != null)
69: logger.log(name + " " + message, throwable);
70: else {
71: System.out.println(name + " " + message);
72: throwable.printStackTrace(System.out);
73: }
74:
75: }
76:
77: private Logger getLogger() {
78:
79: if (connector != null) {
80: return connector.getContainer().getLogger();
81: } else {
82: return null;
83: }
84:
85: }
86:
87: }
|