View Javadoc
1   /*
2    * Copyright 2018 SPF4J.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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  package org.spf4j.test.log;
17  
18  import com.google.common.base.Throwables;
19  import java.util.Collections;
20  import java.util.List;
21  import javax.annotation.Nonnull;
22  import javax.annotation.Nullable;
23  import javax.annotation.ParametersAreNonnullByDefault;
24  import javax.annotation.concurrent.ThreadSafe;
25  import org.slf4j.Marker;
26  import org.spf4j.log.Level;
27  import org.spf4j.log.Slf4jLogRecordImpl;
28  
29  /**
30   * @author Zoltan Farkas
31   */
32  @ParametersAreNonnullByDefault
33  @ThreadSafe
34  public final class TestLogRecordImpl extends Slf4jLogRecordImpl implements TestLogRecord {
35  
36    public TestLogRecordImpl(final String loggerName, final Level level,
37            final String format, final Object... arguments) {
38      this(loggerName, level, null, format, arguments);
39    }
40  
41    public TestLogRecordImpl(final String loggerName, final Level level,
42            @Nullable final Marker marker, final String format, final Object... arguments) {
43      super(loggerName, level, marker, format, arguments);
44    }
45  
46  
47    @Nonnull
48    @Override
49    public List<Throwable> getExtraThrowableChain() {
50      Throwable extraThrowable = getExtraThrowable();
51      if (extraThrowable == null) {
52        return Collections.EMPTY_LIST;
53      }
54      return Throwables.getCausalChain(extraThrowable);
55    }
56  
57    @Override
58    public String toString() {
59      StringBuilder result = new StringBuilder(128);
60      LogPrinter.PRINTER.printTo(result, this, "");
61      return result.toString();
62    }
63  
64  }