1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.cling.logging; 20 21 import org.codehaus.plexus.logging.Logger; 22 import org.codehaus.plexus.logging.LoggerManager; 23 import org.slf4j.ILoggerFactory; 24 import org.slf4j.LoggerFactory; 25 26 /** 27 * Use an SLF4J {@link ILoggerFactory} as a backing for a Plexus 28 * {@link LoggerManager}, 29 * ignoring Plexus logger API parts that are not classical and probably not really used. 30 * 31 * @since 3.1 32 */ 33 public class Slf4jLoggerManager implements LoggerManager { 34 35 private final ILoggerFactory loggerFactory; 36 37 public Slf4jLoggerManager() { 38 loggerFactory = LoggerFactory.getILoggerFactory(); 39 } 40 41 @Override 42 public Logger getLoggerForComponent(String role) { 43 return new Slf4jLogger(loggerFactory.getLogger(role)); 44 } 45 46 /** 47 * The logger name for a component with a non-null hint is <code>role.hint</code>. 48 * <b>Warning</b>: this does not conform to logger name as class name convention. 49 * (and what about <code>null</code> and <code>default</code> hint equivalence?) 50 */ 51 @Override 52 public Logger getLoggerForComponent(String role, String hint) { 53 return (null == hint 54 ? getLoggerForComponent(role) 55 : new Slf4jLogger(loggerFactory.getLogger(role + '.' + hint))); 56 } 57 58 // 59 // Trying to give loggers back is a bad idea. Ceki said so :-) 60 // notice to self: what was this method supposed to do? 61 // 62 /** 63 * <b>Warning</b>: ignored. 64 */ 65 @Override 66 public void returnComponentLogger(String role) {} 67 68 /** 69 * <b>Warning</b>: ignored. 70 */ 71 @Override 72 public void returnComponentLogger(String role, String hint) {} 73 74 /** 75 * <b>Warning</b>: ignored (always return <code>0</code>). 76 */ 77 @Override 78 public int getThreshold() { 79 return 0; 80 } 81 82 /** 83 * <b>Warning</b>: ignored. 84 */ 85 @Override 86 public void setThreshold(int threshold) {} 87 88 /** 89 * <b>Warning</b>: ignored. 90 */ 91 @Override 92 public void setThresholds(int threshold) {} 93 94 /** 95 * <b>Warning</b>: ignored (always return <code>0</code>). 96 */ 97 @Override 98 public int getActiveLoggerCount() { 99 return 0; 100 } 101 }