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
18 package org.apache.commons.logging.simple;
19
20 import java.text.DateFormat;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.commons.logging.impl.SimpleLog;
25
26 /**
27 * <p>Decorated instance of SimpleLog to expose internal state and
28 * support buffered output.</p>
29 */
30
31 public class DecoratedSimpleLog extends SimpleLog {
32
33 /**
34 * Generated serial version ID.
35 */
36 private static final long serialVersionUID = 196544280770017153L;
37
38 // Cache of logged records
39 protected ArrayList<LogRecord> cache = new ArrayList<>();
40
41 public DecoratedSimpleLog(final String name) {
42 super(name);
43 }
44
45 // Clear cache
46 public void clearCache() {
47 cache.clear();
48 }
49
50 // Return cache
51 public List<LogRecord> getCache() {
52 return this.cache;
53 }
54
55 public String getDateTimeFormat() {
56 return dateTimeFormat;
57 }
58
59 public DateFormat getDateTimeFormatter() {
60 return dateFormatter;
61 }
62
63 public String getLogName() {
64 return logName;
65 }
66
67 public boolean getShowDateTime() {
68 return showDateTime;
69 }
70
71 public boolean getShowShortName() {
72 return showShortName;
73 }
74
75 // Cache logged messages
76 @Override
77 protected void log(final int type, final Object message, final Throwable t) {
78
79 super.log(type, message, t);
80 cache.add(new LogRecord(type, message, t));
81
82 }
83
84 }