View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.test.util;
20  
21  import java.io.PrintStream;
22  
23  import org.eclipse.aether.spi.log.Logger;
24  import org.eclipse.aether.spi.log.LoggerFactory;
25  
26  /**
27   * A logger factory that writes to some {@link PrintStream}.
28   *
29   * @deprecated Use SLF4J instead
30   */
31  @Deprecated
32  public final class TestLoggerFactory implements LoggerFactory {
33  
34      private final Logger logger;
35  
36      /**
37       * Creates a new logger factory that writes to {@link System#out}.
38       */
39      public TestLoggerFactory() {
40          this(null);
41      }
42  
43      /**
44       * Creates a new logger factory that writes to the specified print stream.
45       */
46      public TestLoggerFactory(PrintStream out) {
47          logger = new TestLogger(out);
48      }
49  
50      public Logger getLogger(String name) {
51          return logger;
52      }
53  
54      private static final class TestLogger implements Logger {
55  
56          private final PrintStream out;
57  
58          TestLogger(PrintStream out) {
59              this.out = (out != null) ? out : System.out;
60          }
61  
62          public boolean isWarnEnabled() {
63              return true;
64          }
65  
66          public void warn(String msg, Throwable error) {
67              out.println("[WARN] " + msg);
68              if (error != null) {
69                  error.printStackTrace(out);
70              }
71          }
72  
73          public void warn(String msg) {
74              warn(msg, null);
75          }
76  
77          public boolean isDebugEnabled() {
78              return true;
79          }
80  
81          public void debug(String msg, Throwable error) {
82              out.println("[DEBUG] " + msg);
83              if (error != null) {
84                  error.printStackTrace(out);
85              }
86          }
87  
88          public void debug(String msg) {
89              debug(msg, null);
90          }
91      }
92  }