001package org.eclipse.aether.internal.test.util; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.PrintStream; 023 024import org.eclipse.aether.spi.log.Logger; 025import org.eclipse.aether.spi.log.LoggerFactory; 026 027/** 028 * A logger factory that writes to some {@link PrintStream}. 029 */ 030public final class TestLoggerFactory 031 implements LoggerFactory 032{ 033 034 private final Logger logger; 035 036 /** 037 * Creates a new logger factory that writes to {@link System#out}. 038 */ 039 public TestLoggerFactory() 040 { 041 this( null ); 042 } 043 044 /** 045 * Creates a new logger factory that writes to the specified print stream. 046 */ 047 public TestLoggerFactory( PrintStream out ) 048 { 049 logger = new TestLogger( out ); 050 } 051 052 public Logger getLogger( String name ) 053 { 054 return logger; 055 } 056 057 private static final class TestLogger 058 implements Logger 059 { 060 061 private final PrintStream out; 062 063 TestLogger( PrintStream out ) 064 { 065 this.out = ( out != null ) ? out : System.out; 066 } 067 068 public boolean isWarnEnabled() 069 { 070 return true; 071 } 072 073 public void warn( String msg, Throwable error ) 074 { 075 out.println( "[WARN] " + msg ); 076 if ( error != null ) 077 { 078 error.printStackTrace( out ); 079 } 080 } 081 082 public void warn( String msg ) 083 { 084 warn( msg, null ); 085 } 086 087 public boolean isDebugEnabled() 088 { 089 return true; 090 } 091 092 public void debug( String msg, Throwable error ) 093 { 094 out.println( "[DEBUG] " + msg ); 095 if ( error != null ) 096 { 097 error.printStackTrace( out ); 098 } 099 } 100 101 public void debug( String msg ) 102 { 103 debug( msg, null ); 104 } 105 106 } 107 108}