You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "John Lussmyer (JIRA)" <ji...@apache.org> on 2014/08/29 21:13:53 UTC

[jira] [Comment Edited] (LOG4J2-794) configurationFile with space in name will fail to be loaded

    [ https://issues.apache.org/jira/browse/LOG4J2-794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14115686#comment-14115686 ] 

John Lussmyer edited comment on LOG4J2-794 at 8/29/14 7:13 PM:
---------------------------------------------------------------

This is the change I made to ConfigurationFactory that makes it work for us.  
{noformat}
@@ -281,7 +281,7 @@
      * @param loader The default ClassLoader to use.
      * @return The InputSource to use to read the configuration.
      */
-    protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) {
+    protected ConfigurationSource getInputFromString( String config, final ClassLoader loader) {
         try {
             final URL url = new URL(config);
             return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI()));
@@ -289,6 +289,9 @@
             final ConfigurationSource source = getInputFromResource(config, loader);
             if (source == null) {
                 try {
+            	  if (config.startsWith("file:")) {
+            		  config = config.substring(5);
+            	  }
                     final File file = new File(config);
                     return new ConfigurationSource(new FileInputStream(file), file);
                 } catch (final FileNotFoundException fnfe) {
{noformat}


was (Author: casadelgato):
This is the change I made to ConfigurationFactory that makes it work for us.  

@@ -281,7 +281,7 @@
      * @param loader The default ClassLoader to use.
      * @return The InputSource to use to read the configuration.
      */
-    protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) {
+    protected ConfigurationSource getInputFromString( String config, final ClassLoader loader) {
         try {
             final URL url = new URL(config);
             return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI()));
@@ -289,6 +289,9 @@
             final ConfigurationSource source = getInputFromResource(config, loader);
             if (source == null) {
                 try {
+            	  if (config.startsWith("file:")) {
+            		  config = config.substring(5);
+            	  }
                     final File file = new File(config);
                     return new ConfigurationSource(new FileInputStream(file), file);
                 } catch (final FileNotFoundException fnfe) {


> configurationFile with space in name will fail to be loaded
> -----------------------------------------------------------
>
>                 Key: LOG4J2-794
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-794
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.0, 2.0.1
>         Environment: Windows 7
>            Reporter: John Lussmyer
>
> We've set the System Property "log4j.configurationFile" to be {{"C:\\Repo\\Metrix\\Logs Two\\Metrix.xml"}}
> When ConfigurationFactory.getInputFromString() tries to load it, it fails.
> This appears to be due to the attempt to open it as a simple file,
> "final File file = new File(config)"
> passes the string {{"file:C:\\Repo\\Metrix\\Logs Two\\Metrix.xml"}}, which File() does not understand.
> This results in:
> {code}
> java.io.FileNotFoundException: file:C:\Repo\Metrix\Logs Two\Metrix.xml (The filename, directory name, or volume label syntax is incorrect)
> {code}
> (Note: This is actually with the log4j 2.0.1 jar files, but the "Affects Version" won't let me use that version.)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org