1 /* 2 * Copyright 2006-2012 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.maven.util; 17 18 import java.util.logging.LogManager; 19 20 import org.apache.maven.plugin.logging.Log; 21 22 /** 23 * Configures the log4j framework with the logging information. 24 * 25 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 26 * @version $Revision:591 $ 27 */ 28 public class SunLoggerConfigurator 29 { 30 // ********************************* Fields ********************************* 31 32 // --- constants ------------------------------------------------------------ 33 34 // --- members -------------------------------------------------------------- 35 36 // ****************************** Initializer ******************************* 37 38 // ****************************** Constructors ****************************** 39 40 /** 41 * Default constructor. 42 */ 43 public SunLoggerConfigurator() 44 { 45 } 46 47 // ****************************** Inner Classes ***************************** 48 49 // ********************************* Methods ******************************** 50 51 // --- init ----------------------------------------------------------------- 52 53 // --- get&set -------------------------------------------------------------- 54 55 // --- business ------------------------------------------------------------- 56 57 /** 58 * Reads a pre-configured configuration file. 59 * 60 * @param log the Maven logger to use for logging. 61 * @param level the new level to set the Java logging system to. 62 */ 63 public void configure(final Log log, final String level) 64 { 65 try 66 { 67 final String file = "logging-" + level + ".properties"; 68 if(log.isDebugEnabled()) 69 { 70 log.debug("Reading config file '" + file + "'..."); 71 } 72 final LogManager logManager = LogManager.getLogManager(); 73 logManager 74 .readConfiguration(LoggingUtils.class.getResourceAsStream(file)); 75 } 76 catch (final Exception e) 77 { 78 if (log.isWarnEnabled()) 79 { 80 log.warn("Cannot configure logger.", e); 81 } 82 } 83 } 84 85 // --- object basics -------------------------------------------------------- 86 87 }