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