-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from jamezp/logdir
Allow for better overriding of the logging configuration.
- Loading branch information
Showing
7 changed files
with
143 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
bootstrap/src/main/java/org/jboss/forge/bootstrap/LoggingConfigurationLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2013, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.forge.bootstrap; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FilenameFilter; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
import org.jboss.forge.container.util.OperatingSystemUtils; | ||
import org.jboss.logmanager.ConfigurationLocator; | ||
|
||
/** | ||
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> | ||
*/ | ||
public class LoggingConfigurationLocator implements ConfigurationLocator | ||
{ | ||
static final FilenameFilter LOGGING_CONFIG_FILTER = new FilenameFilter() | ||
{ | ||
@Override | ||
public boolean accept(final File dir, final String name) | ||
{ | ||
return name.equals("logging.properties"); | ||
} | ||
}; | ||
|
||
@Override | ||
public InputStream findConfiguration() throws IOException | ||
{ | ||
// First look for the property | ||
final String propLoc = System.getProperty("logging.configuration"); | ||
if (propLoc != null) try | ||
{ | ||
return new URL(propLoc).openStream(); | ||
} catch (IOException e) | ||
{ | ||
System.err.printf("Unable to read the logging configuration from '%s' (%s)%n", propLoc, e); | ||
} | ||
File[] files = null; | ||
// Second attempt to find the configuration in the users .forge directory | ||
final File userForgeDir = OperatingSystemUtils.getUserForgeDir(); | ||
// Look for a logging.properties file | ||
if (userForgeDir.isDirectory()) | ||
{ | ||
files = userForgeDir.listFiles(LOGGING_CONFIG_FILTER); | ||
if (files != null && files.length > 0) | ||
{ | ||
return new FileInputStream(files[0]); | ||
} | ||
} | ||
// Finally default to $FORGE_HOME/logging.properties | ||
final File forgeHomeDir = OperatingSystemUtils.getForgeHomeDir(); | ||
// Look for a logging.properties file | ||
if (forgeHomeDir.isDirectory()) | ||
{ | ||
files = forgeHomeDir.listFiles(LOGGING_CONFIG_FILTER); | ||
} | ||
// If the file was found, return it, otherwise return null | ||
if (files != null && files.length > 0) | ||
{ | ||
return new FileInputStream(files[0]); | ||
} | ||
System.err.println("No logging configuration was found."); | ||
return null; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
bootstrap/src/main/resources/META-INF/services/org.jboss.logmanager.ConfigurationLocator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.jboss.forge.bootstrap.LoggingConfigurationLocator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters