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 * 030 * @deprecated Use SLF4J instead 031 */ 032@Deprecated 033public final class TestLoggerFactory 034 implements LoggerFactory 035{ 036 037 private final Logger logger; 038 039 /** 040 * Creates a new logger factory that writes to {@link System#out}. 041 */ 042 public TestLoggerFactory() 043 { 044 this( null ); 045 } 046 047 /** 048 * Creates a new logger factory that writes to the specified print stream. 049 */ 050 public TestLoggerFactory( PrintStream out ) 051 { 052 logger = new TestLogger( out ); 053 } 054 055 public Logger getLogger( String name ) 056 { 057 return logger; 058 } 059 060 private static final class TestLogger 061 implements Logger 062 { 063 064 private final PrintStream out; 065 066 TestLogger( PrintStream out ) 067 { 068 this.out = ( out != null ) ? out : System.out; 069 } 070 071 public boolean isWarnEnabled() 072 { 073 return true; 074 } 075 076 public void warn( String msg, Throwable error ) 077 { 078 out.println( "[WARN] " + msg ); 079 if ( error != null ) 080 { 081 error.printStackTrace( out ); 082 } 083 } 084 085 public void warn( String msg ) 086 { 087 warn( msg, null ); 088 } 089 090 public boolean isDebugEnabled() 091 { 092 return true; 093 } 094 095 public void debug( String msg, Throwable error ) 096 { 097 out.println( "[DEBUG] " + msg ); 098 if ( error != null ) 099 { 100 error.printStackTrace( out ); 101 } 102 } 103 104 public void debug( String msg ) 105 { 106 debug( msg, null ); 107 } 108 109 } 110 111}