Debian Codegraph @

src/org/apache/commons/jcs3/engine/logging/CacheEventLoggerDebugLogger.java

raw symbols SCIP
1 package org.apache.commons.jcs3.engine.logging;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.jcs3.engine.logging.behavior.ICacheEvent;
23 import org.apache.commons.jcs3.engine.logging.behavior.ICacheEventLogger;
24 import org.apache.commons.jcs3.log.Log;
25 import org.apache.commons.jcs3.log.LogManager;
26
27 /**
28 * This implementation simple logs to a logger at debug level, for all events. It's mainly
29 * for testing. It isn't very useful otherwise.
30 */
31 public class CacheEventLoggerDebugLogger
32 implements ICacheEventLogger
33 {
34 /** This is the name of the category. */
35 private String logCategoryName = CacheEventLoggerDebugLogger.class.getName();
36
37 /** The logger. This is recreated on set logCategoryName */
38 private Log log = LogManager.getLog( logCategoryName );
39
40 /**
41 * @param source
42 * @param region
43 * @param eventName
44 * @param optionalDetails
45 * @param key
46 * @return ICacheEvent
47 */
48 @Override
49 public <T> ICacheEvent<T> createICacheEvent( final String source, final String region, final String eventName,
50 final String optionalDetails, final T key )
51 {
52 final ICacheEvent<T> event = new CacheEvent<>();
53 event.setSource( source );
54 event.setRegion( region );
55 event.setEventName( eventName );
56 event.setOptionalDetails( optionalDetails );
57 event.setKey( key );
58
59 return event;
60 }
61
62 /**
63 * @param source
64 * @param eventName
65 * @param optionalDetails
66 */
67 @Override
68 public void logApplicationEvent( final String source, final String eventName, final String optionalDetails )
69 {
70 log.debug( "{0} | {1} | {2}", source, eventName, optionalDetails );
71 }
72
73 /**
74 * @param source
75 * @param eventName
76 * @param errorMessage
77 */
78 @Override
79 public void logError( final String source, final String eventName, final String errorMessage )
80 {
81 log.debug( "{0} | {1} | {2}", source, eventName, errorMessage );
82 }
83
84 /**
85 * @param event
86 */
87 @Override
88 public <T> void logICacheEvent( final ICacheEvent<T> event )
89 {
90 log.debug( event );
91 }
92
93 /**
94 * @param logCategoryName
95 */
96 public synchronized void setLogCategoryName( final String logCategoryName )
97 {
98 if ( logCategoryName != null && !logCategoryName.equals( this.logCategoryName ) )
99 {
100 this.logCategoryName = logCategoryName;
101 log = LogManager.getLog( logCategoryName );
102 }
103 }
104 }