1 package org.eclipse.aether.internal.test.util;
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 java.io.PrintStream;
23
24 import org.eclipse.aether.spi.log.Logger;
25 import org.eclipse.aether.spi.log.LoggerFactory;
26
27 /**
28 * A logger factory that writes to some {@link PrintStream}.
29 *
30 * @deprecated Use SLF4J instead
31 */
32 @Deprecated
33 public final class TestLoggerFactory
34 implements LoggerFactory
35 {
36
37 private final Logger logger;
38
39 /**
40 * Creates a new logger factory that writes to {@link System#out}.
41 */
42 public TestLoggerFactory()
43 {
44 this( null );
45 }
46
47 /**
48 * Creates a new logger factory that writes to the specified print stream.
49 */
50 public TestLoggerFactory( PrintStream out )
51 {
52 logger = new TestLogger( out );
53 }
54
55 public Logger getLogger( String name )
56 {
57 return logger;
58 }
59
60 private static final class TestLogger
61 implements Logger
62 {
63
64 private final PrintStream out;
65
66 TestLogger( PrintStream out )
67 {
68 this.out = ( out != null ) ? out : System.out;
69 }
70
71 public boolean isWarnEnabled()
72 {
73 return true;
74 }
75
76 public void warn( String msg, Throwable error )
77 {
78 out.println( "[WARN] " + msg );
79 if ( error != null )
80 {
81 error.printStackTrace( out );
82 }
83 }
84
85 public void warn( String msg )
86 {
87 warn( msg, null );
88 }
89
90 public boolean isDebugEnabled()
91 {
92 return true;
93 }
94
95 public void debug( String msg, Throwable error )
96 {
97 out.println( "[DEBUG] " + msg );
98 if ( error != null )
99 {
100 error.printStackTrace( out );
101 }
102 }
103
104 public void debug( String msg )
105 {
106 debug( msg, null );
107 }
108
109 }
110
111 }