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.cli.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 org.slf4j.ILoggerFactory} as a backing for a Plexus 28 * {@link org.codehaus.plexus.logging.LoggerManager}, 29 * ignoring Plexus logger API parts that are not classical and probably not really used. 30 * 31 * @author Jason van Zyl 32 * @since 3.1 33 */ 34 public class Slf4jLoggerManager implements LoggerManager { 35 36 private ILoggerFactory loggerFactory; 37 38 public Slf4jLoggerManager() { 39 loggerFactory = LoggerFactory.getILoggerFactory(); 40 } 41 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 public Logger getLoggerForComponent(String role, String hint) { 52 return (null == hint 53 ? getLoggerForComponent(role) 54 : new Slf4jLogger(loggerFactory.getLogger(role + '.' + hint))); 55 } 56 57 // 58 // Trying to give loggers back is a bad idea. Ceki said so :-) 59 // notice to self: what was this method supposed to do? 60 // 61 /** 62 * <b>Warning</b>: ignored. 63 */ 64 public void returnComponentLogger(String role) {} 65 66 /** 67 * <b>Warning</b>: ignored. 68 */ 69 public void returnComponentLogger(String role, String hint) {} 70 71 /** 72 * <b>Warning</b>: ignored (always return <code>0</code>). 73 */ 74 public int getThreshold() { 75 return 0; 76 } 77 78 /** 79 * <b>Warning</b>: ignored. 80 */ 81 public void setThreshold(int threshold) {} 82 83 /** 84 * <b>Warning</b>: ignored. 85 */ 86 public void setThresholds(int threshold) {} 87 88 /** 89 * <b>Warning</b>: ignored (always return <code>0</code>). 90 */ 91 public int getActiveLoggerCount() { 92 return 0; 93 } 94 }