001package org.apache.maven.cli.logging; 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 org.codehaus.plexus.logging.Logger; 023import org.codehaus.plexus.logging.LoggerManager; 024import org.slf4j.ILoggerFactory; 025import org.slf4j.LoggerFactory; 026 027/** 028 * Use an SLF4J {@link org.slf4j.ILoggerFactory} as a backing for a Plexus 029 * {@link org.codehaus.plexus.logging.LoggerManager}, 030 * ignoring Plexus logger API parts that are not classical and probably not really used. 031 * 032 * @author Jason van Zyl 033 * @since 3.1 034 */ 035public class Slf4jLoggerManager 036 implements LoggerManager 037{ 038 039 private ILoggerFactory loggerFactory; 040 041 public Slf4jLoggerManager() 042 { 043 loggerFactory = LoggerFactory.getILoggerFactory(); 044 } 045 046 public Logger getLoggerForComponent( String role ) 047 { 048 return new Slf4jLogger( loggerFactory.getLogger( role ) ); 049 } 050 051 /** 052 * The logger name for a component with a non-null hint is <code>role.hint</code>. 053 * <b>Warning</b>: this does not conform to logger name as class name convention. 054 * (and what about <code>null</code> and <code>default</code> hint equivalence?) 055 */ 056 public Logger getLoggerForComponent( String role, String hint ) 057 { 058 return ( null == hint 059 ? getLoggerForComponent( role ) 060 : new Slf4jLogger( loggerFactory.getLogger( role + '.' + hint ) ) ); 061 } 062 063 // 064 // Trying to give loggers back is a bad idea. Ceki said so :-) 065 // notice to self: what was this method supposed to do? 066 // 067 /** 068 * <b>Warning</b>: ignored. 069 */ 070 public void returnComponentLogger( String role ) 071 { 072 } 073 074 /** 075 * <b>Warning</b>: ignored. 076 */ 077 public void returnComponentLogger( String role, String hint ) 078 { 079 } 080 081 /** 082 * <b>Warning</b>: ignored (always return <code>0</code>). 083 */ 084 public int getThreshold() 085 { 086 return 0; 087 } 088 089 /** 090 * <b>Warning</b>: ignored. 091 */ 092 public void setThreshold( int threshold ) 093 { 094 } 095 096 /** 097 * <b>Warning</b>: ignored. 098 */ 099 public void setThresholds( int threshold ) 100 { 101 } 102 103 /** 104 * <b>Warning</b>: ignored (always return <code>0</code>). 105 */ 106 public int getActiveLoggerCount() 107 { 108 return 0; 109 } 110 111}