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