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     */
019    
020    package org.apache.geronimo.genesis.logging;
021    
022    import org.apache.commons.logging.Log;
023    import org.apache.commons.logging.LogFactory;
024    
025    /**
026     * Maven plugin logging helpers to initialize and reset logging.
027     *
028     * @version $Rev: 470159 $ $Date: 2006-11-01 17:19:16 -0800 (Wed, 01 Nov 2006) $
029     */
030    public class Logging
031    {
032        private static boolean initialized;
033    
034        public synchronized static void init() {
035            if (!initialized) {
036                LogFactory.releaseAll();
037    
038                // Setup the delegating log
039                System.setProperty("org.apache.commons.logging.Log", "org.apache.geronimo.genesis.logging.DelegatingLog");
040    
041                // Make sure that Geronimo bootstrap logging does not clobber our logging
042                System.setProperty("geronimo.bootstrap.logging.enabled", "false");
043                
044                Log log = LogFactory.getLog(Logging.class);
045                log.debug("Initialized");
046    
047                initialized = true;
048            }
049        }
050    
051        public synchronized static void reset() {
052            if (initialized) {
053                Log log = LogFactory.getLog(Logging.class);
054                log.debug("Resetting");
055    
056                LogFactory.releaseAll();
057    
058                // Restore a reasonable default log impl
059                System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
060    
061                // Make SimpleLog look more like Maven logs
062                System.setProperty("org.apache.commons.logging.simplelog.showShortLogname", "false");
063                
064                // Restore default Geornimo bootstrap behavior
065                System.getProperties().remove("geronimo.bootstrap.logging.enabled");
066    
067                initialized = false;
068            }
069        }
070    }