KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > logging > log4j > MockLogger


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 package org.apache.geronimo.system.logging.log4j;
18
19 import org.apache.log4j.Logger;
20 import org.apache.log4j.Priority;
21
22 /**
23  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
24  */

25 final class MockLogger extends Logger {
26     final static String JavaDoc MOCK_NAME = "MOCK_NAME";
27     boolean isEnabledForCalled = false;
28     Priority calledWithPriority = null;
29     boolean logCalled = false;
30     Object JavaDoc calledWithObject;
31     Throwable JavaDoc calledWithThrowable;
32     String JavaDoc calledWithString;
33     boolean isDebugEnabledCalled;
34     boolean isInfoEnabledCalled;
35     private boolean debugEnabled = false;
36     private boolean infoEnabled = false;
37     private boolean enabledFor = false;
38     final Object JavaDoc isEnabledForLock = new Object JavaDoc();
39
40     MockLogger(String JavaDoc str) {
41         super(str);
42     }
43
44     public boolean isEnabledFor(Priority priority) {
45         synchronized (isEnabledForLock) {
46             isEnabledForCalled = true;
47             calledWithPriority = priority;
48             if (isEnabledForCalled && isDebugEnabledCalled && isInfoEnabledCalled) isEnabledForLock.notifyAll();
49             return enabledFor;
50         }
51     }
52
53     public boolean isDebugEnabled() {
54         synchronized (isEnabledForLock) {
55             isDebugEnabledCalled = true;
56             if (isEnabledForCalled && isDebugEnabledCalled && isInfoEnabledCalled) isEnabledForLock.notifyAll();
57             return debugEnabled;
58         }
59     }
60
61     public boolean isInfoEnabled() {
62         synchronized (isEnabledForLock) {
63             isInfoEnabledCalled = true;
64             if (isEnabledForCalled && isDebugEnabledCalled && isInfoEnabledCalled) isEnabledForLock.notifyAll();
65             return infoEnabled;
66         }
67     }
68
69     public void log(String JavaDoc s, Priority priority, Object JavaDoc o, Throwable JavaDoc throwable) {
70         logCalled = true;
71         calledWithString = s;
72         calledWithPriority = priority;
73         calledWithObject = o;
74         calledWithThrowable = throwable;
75     }
76
77     public void setEnabledFor(boolean enabledFor) {
78         this.enabledFor = enabledFor;
79     }
80
81     public void setDebugEnabled(boolean debugEnabled) {
82         this.debugEnabled = debugEnabled;
83     }
84
85     public void setInfoEnabled(boolean infoEnabled) {
86         this.infoEnabled = infoEnabled;
87     }
88 }
89
Popular Tags