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 public final class TestLoggerFactory
31 implements LoggerFactory
32 {
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 {
41 this( null );
42 }
43
44 /**
45 * Creates a new logger factory that writes to the specified print stream.
46 */
47 public TestLoggerFactory( PrintStream out )
48 {
49 logger = new TestLogger( out );
50 }
51
52 public Logger getLogger( String name )
53 {
54 return logger;
55 }
56
57 private static final class TestLogger
58 implements Logger
59 {
60
61 private final PrintStream out;
62
63 public TestLogger( PrintStream out )
64 {
65 this.out = ( out != null ) ? out : System.out;
66 }
67
68 public boolean isWarnEnabled()
69 {
70 return true;
71 }
72
73 public void warn( String msg, Throwable error )
74 {
75 out.println( "[WARN] " + msg );
76 if ( error != null )
77 {
78 error.printStackTrace( out );
79 }
80 }
81
82 public void warn( String msg )
83 {
84 warn( msg, null );
85 }
86
87 public boolean isDebugEnabled()
88 {
89 return true;
90 }
91
92 public void debug( String msg, Throwable error )
93 {
94 out.println( "[DEBUG] " + msg );
95 if ( error != null )
96 {
97 error.printStackTrace( out );
98 }
99 }
100
101 public void debug( String msg )
102 {
103 debug( msg, null );
104 }
105
106 }
107
108 }