You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Shawn Heisey <ap...@elyograg.org> on 2018/07/03 15:10:03 UTC
Odd problem starting program with log4j2 on Windows
I'm investigating a problem a user is having with starting the latest
release of Solr on Windows. This release is the first one we've made
after upgrading log4j from 1.2.x to 2.11.0.
I have double-checked that the script starts the program with this
commandline option:
-Dlog4j.configurationFile="file:C:\Users\sheisey\Downloads\solr-7.4.0\server\scripts\cloud-scripts\log4j2.xml"
This is what's actually in the .cmd file ... I used the 'echo' command
to verify what the full commandline expands to:
-Dlog4j.configurationFile="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j2.xml"
An exception is sent to stdout, which I will provide at the end of this
message.
In the exception, you may notice that the path it says it can't find has
TWO "file:" elements in it, and two paths complete with "C:\" in them.
The value of DEFAULT_SERVER_DIR is
C:\Users\sheisey\Downloads\solr-7.4.0\server ... which is what's before
the second "file:" in the exception, with the backslashes converted to
forward slashes. Unless something is going very wrong with the windows
command script language so that the commandline isn't actually what I've
double-checked it to be, it looks like a problem in log4j ... one that
might only exist on Windows.
I'm running this on Windows 7 enterprise edition, the user on the Solr
mailing list is running it on Windows 10 enterprise edition and running
into the same problem.
If I remove the "file:" prefix from the value assigned to the system
property, so that it is a bare Windows path, everything works properly.
This workaround was mentioned by the user on the Solr mailing list.
The same thing on Linux appears to work correctly. This is the
commandline option that ends up being used there:
-Dlog4j.configurationFile=file:/index/src/solr-7.4.0/server/scripts/cloud-scripts/log4j2.xml
Here's the exception that I get on Windows:
ERROR StatusLogger Unable to access
file:/C:/Users/sheisey/Downloads/solr-7.4.0/server/file:C:/Users/sheisey/Downloads/solr-7.4.0/server/scripts/cloud-scripts/log4j2.xml
java.io.FileNotFoundException:
C:\Users\sheisey\Downloads\solr-7.4.0\server\file:C:\Users\sheisey\Downloads\solr-7.4.0\server\scripts\cloud-scripts\log4j2.xml
(The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at
sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at
sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at java.net.URL.openStream(URL.java:1045)
at
org.apache.logging.log4j.core.config.ConfigurationSource.fromUri(ConfigurationSource.java:247)
at
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:404)
at
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:346)
at
org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:260)
at
org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:615)
at
org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at
org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at
org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
at
org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
at
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at
org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at org.apache.solr.util.SolrCLI.<clinit>(SolrCLI.java:228)
Is there any other information I can provide? You can download Solr at
http://lucene.apache.org/solr if you need to reproduce and investigate
the scripting that comes with it.
Thanks,
Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Remko Popma <re...@gmail.com>.
I’m not sure. The weird behavior can be expected, given that the specified string is neither a correct path, nor a correct URL:
new File(“file:C:\\temp\\some.file”).toURI()
It’s simply invalid input.
Should log4j attempt to handle this invalid input?
(Shameless plug) Every java main() method deserves http://picocli.info
> On Jul 6, 2018, at 13:11, Ralph Goers <ra...@dslextreme.com> wrote:
>
> I suppose we could look for that and fix it, but that would mean having Windows specific code.
>
> Ralph
>
>> On Jul 5, 2018, at 9:10 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>>
>> So that is some weirdness with Java itself, and only on Windows.
>>
>> Ralph
>>
>>> On Jul 5, 2018, at 7:34 PM, Remko Popma <re...@gmail.com> wrote:
>>>
>>> I found that the problem can be reproduced with this:
>>>
>>> new File(“file:C:\\temp\\some.file”).toURI()
>>>
>>> If you print the above it shows:
>>>
>>> file:/C:/my/current/directory/file:C:/temp/some.file
>>>
>>>
>>> So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
>>>
>>>
>>> (Shameless plug) Every java main() method deserves http://picocli.info
>>>
>>>> On Jul 6, 2018, at 10:52, Gary Gregory <ga...@gmail.com> wrote:
>>>>
>>>> Can't URL contain commas?
>>>>
>>>> Gary
>>>>
>>>>> On Thu, Jul 5, 2018, 18:11 Ralph Goers <ra...@dslextreme.com> wrote:
>>>>>
>>>>> Here is what Log4j does:
>>>>>
>>>>> If the property is specified first see if it contains any commas, if so
>>>>> then there will be multiple configuration files, which essentially does
>>>>> what follows for each file. If not then try to convert it to a URI using
>>>>> the following code:
>>>>>
>>>>> public static URI toURI(final String path) {
>>>>> try {
>>>>> // Resolves absolute URI
>>>>> return new URI(path);
>>>>> } catch (final URISyntaxException e) {
>>>>> // A file path or a Apache Commons VFS URL might contain blanks.
>>>>> // A file path may start with a driver letter
>>>>> try {
>>>>> final URL url = new URL(path);
>>>>> return new URI(url.getProtocol(), url.getHost(),
>>>>> url.getPath(), null);
>>>>> } catch (MalformedURLException | URISyntaxException nestedEx) {
>>>>> return new File(path).toURI();
>>>>> }
>>>>> }
>>>>> }
>>>>>
>>>>> The URI is then converted to a ConfigurationSource using:
>>>>> public static ConfigurationSource fromUri(final URI configLocation) {
>>>>> final File configFile = FileUtils.fileFromUri(configLocation);
>>>>> if (configFile != null && configFile.exists() && configFile.canRead())
>>>>> {
>>>>> try {
>>>>> return new ConfigurationSource(new
>>>>> FileInputStream(configFile), configFile);
>>>>> } catch (final FileNotFoundException ex) {
>>>>> ConfigurationFactory.LOGGER.error("Cannot locate file {}",
>>>>> configLocation.getPath(), ex);
>>>>> }
>>>>> }
>>>>> if (ConfigurationFactory.isClassLoaderUri(configLocation)) {
>>>>> final ClassLoader loader =
>>>>> LoaderUtil.getThreadContextClassLoader();
>>>>> final String path =
>>>>> ConfigurationFactory.extractClassLoaderUriPath(configLocation);
>>>>> final ConfigurationSource source = fromResource(path, loader);
>>>>> if (source != null) {
>>>>> return source;
>>>>> }
>>>>> }
>>>>> if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing
>>>>> error message thrown by uri.toURL()
>>>>> ConfigurationFactory.LOGGER.error("File not found in file system
>>>>> or classpath: {}", configLocation.toString());
>>>>> return null;
>>>>> }
>>>>> try {
>>>>> return new
>>>>> ConfigurationSource(configLocation.toURL().openStream(),
>>>>> configLocation.toURL());
>>>>> } catch (final MalformedURLException ex) {
>>>>> ConfigurationFactory.LOGGER.error("Invalid URL {}",
>>>>> configLocation.toString(), ex);
>>>>> } catch (final Exception ex) {
>>>>> ConfigurationFactory.LOGGER.error("Unable to access {}",
>>>>> configLocation.toString(), ex);
>>>>> }
>>>>> return null;
>>>>> }
>>>>> I should point out that the stack trace log you are seeing is from the
>>>>> above code failing. If any of the above doesn’t work we then try to create
>>>>> a ConfigurationSource using the following code where config is the value of
>>>>> the property and loader is the ThreadContextClassLoader. So even with the
>>>>> error that is shown it is still possible that the file might be found.
>>>>>
>>>>> protected ConfigurationSource getInputFromString(final String config,
>>>>> final ClassLoader loader) {
>>>>> try {
>>>>> final URL url = new URL(config);
>>>>> return new ConfigurationSource(url.openStream(),
>>>>> FileUtils.fileFromUri(url.toURI()));
>>>>> } catch (final Exception ex) {
>>>>> final ConfigurationSource source =
>>>>> ConfigurationSource.fromResource(config, loader);
>>>>> if (source == null) {
>>>>> try {
>>>>> final File file = new File(config);
>>>>> return new ConfigurationSource(new FileInputStream(file),
>>>>> file);
>>>>> } catch (final FileNotFoundException fnfe) {
>>>>> // Ignore the exception
>>>>> LOGGER.catching(Level.DEBUG, fnfe);
>>>>> }
>>>>> }
>>>>> return source;
>>>>> }
>>>>> }
>>>>> ConfigurationSource.fromResource() tries to locate the resource using
>>>>> ClassLoader.getResource() and then constructs a ConfgurationSource if it
>>>>> can find it. And if all else fails we just pass the string to the File
>>>>> constructor and hope for the best.
>>>>> As you can see we aren’t really manipulating the input string that was
>>>>> provided to us, but we are trying any way we can to convert it into some
>>>>> sort of file we can access. If you see something missing in this logic
>>>>> please let us know.
>>>>>
>>>>> Ralph
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> On Jul 5, 2018, at 1:59 PM, Shawn Heisey <ap...@elyograg.org> wrote:
>>>>>>
>>>>>> On 7/5/2018 11:38 AM, Ralph Goers wrote:
>>>>>>> I have updated the issue you referenced. From what I can tell this is
>>>>> not an issue in Log4j. It is an issue with the way file urls work.
>>>>>>
>>>>>> Thanks for your attention.
>>>>>>
>>>>>> The startup script included with Solr versions before 7.4 (using log4j
>>>>>> 1.2.x) also did not have // in the file: URI for the log4j.properties
>>>>>> file, and it works on both Linux and Windows.
>>>>>>
>>>>>> Something else I found in the RFC you linked:
>>>>>>
>>>>>> The syntax given in Section 2 makes the entire authority component,
>>>>>> including the double slashes "//", optional.
>>>>>>
>>>>>> Reading section 2, I didn't actually see that stated. Maybe it's
>>>>>> something clarified by one of the other referenced RFCs. But if we take
>>>>>> that statement at face value, it seems to be saying that a URI without
>>>>>> // should work. It *does* work on Linux. On Windows, this:
>>>>>>
>>>>>> file:C:\path\to\stuff\log4j2.xml
>>>>>>
>>>>>> gets translated into this:
>>>>>>
>>>>>> file:/$CWD/file:C:/path/to/stuff/log4j2.xml
>>>>>>
>>>>>> Where $CWD is the current working directory. Even the "extra" URI added
>>>>>> as a prefix doesn't have the // in it. If instead we use the following,
>>>>>> it works as expected:
>>>>>>
>>>>>> file://C:\path\to\stuff\log4j2.xml
>>>>>>
>>>>>> If you're sure that there's nothing in log4j code that would result in
>>>>>> the strange location, I'd be willing to accept that this problem is
>>>>>> caused by Java or the OS and not log4j. The fact that this doesn't
>>>>>> happen on Linux is even more reason to believe that. I don't know how
>>>>>> likely it is that log4j contains code that behaves differently based on
>>>>>> detected OS ... but I strongly believe that you'd want to avoid that if
>>>>>> possible.
>>>>>>
>>>>>> I believe that we can safely add // to Solr's command script to solve
>>>>>> this issue for our users, because the value should always be a full
>>>>>> absolute path.
>>>>>>
>>>>>> But I would like to pursue the remaining question: When the RFC is
>>>>>> fully and correctly evaluated, is a "file:" URI without "//" considered
>>>>>> valid? If not, then that ends the discussion. If it is considered
>>>>>> valid, then there's another question: Is it Java, log4j, or Windows that
>>>>>> is causing the problem we've seen?
>>>>>>
>>>>>> Another question: What is the stance of the project on whether non-URI
>>>>>> syntax for the log4j.configurationFile system property will be supported
>>>>>> long-term? I can remember running into a problem with logging
>>>>>> configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
>>>>>> been java.util.logging) where the configuration wasn't found until I
>>>>>> added "file:" to turn it into a URI. I did not use // in the URI. This
>>>>>> is a line from the init script I wrote for Solr 4.x versions (when Solr
>>>>>> did not include a startup script):
>>>>>>
>>>>>> LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
>>>>>>
>>>>>> Thanks,
>>>>>> Shawn
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>>>
>>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>
>>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
I suppose we could look for that and fix it, but that would mean having Windows specific code.
Ralph
> On Jul 5, 2018, at 9:10 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>
> So that is some weirdness with Java itself, and only on Windows.
>
> Ralph
>
>> On Jul 5, 2018, at 7:34 PM, Remko Popma <re...@gmail.com> wrote:
>>
>> I found that the problem can be reproduced with this:
>>
>> new File(“file:C:\\temp\\some.file”).toURI()
>>
>> If you print the above it shows:
>>
>> file:/C:/my/current/directory/file:C:/temp/some.file
>>
>>
>> So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
>>
>>
>> (Shameless plug) Every java main() method deserves http://picocli.info
>>
>>> On Jul 6, 2018, at 10:52, Gary Gregory <ga...@gmail.com> wrote:
>>>
>>> Can't URL contain commas?
>>>
>>> Gary
>>>
>>>> On Thu, Jul 5, 2018, 18:11 Ralph Goers <ra...@dslextreme.com> wrote:
>>>>
>>>> Here is what Log4j does:
>>>>
>>>> If the property is specified first see if it contains any commas, if so
>>>> then there will be multiple configuration files, which essentially does
>>>> what follows for each file. If not then try to convert it to a URI using
>>>> the following code:
>>>>
>>>> public static URI toURI(final String path) {
>>>> try {
>>>> // Resolves absolute URI
>>>> return new URI(path);
>>>> } catch (final URISyntaxException e) {
>>>> // A file path or a Apache Commons VFS URL might contain blanks.
>>>> // A file path may start with a driver letter
>>>> try {
>>>> final URL url = new URL(path);
>>>> return new URI(url.getProtocol(), url.getHost(),
>>>> url.getPath(), null);
>>>> } catch (MalformedURLException | URISyntaxException nestedEx) {
>>>> return new File(path).toURI();
>>>> }
>>>> }
>>>> }
>>>>
>>>> The URI is then converted to a ConfigurationSource using:
>>>> public static ConfigurationSource fromUri(final URI configLocation) {
>>>> final File configFile = FileUtils.fileFromUri(configLocation);
>>>> if (configFile != null && configFile.exists() && configFile.canRead())
>>>> {
>>>> try {
>>>> return new ConfigurationSource(new
>>>> FileInputStream(configFile), configFile);
>>>> } catch (final FileNotFoundException ex) {
>>>> ConfigurationFactory.LOGGER.error("Cannot locate file {}",
>>>> configLocation.getPath(), ex);
>>>> }
>>>> }
>>>> if (ConfigurationFactory.isClassLoaderUri(configLocation)) {
>>>> final ClassLoader loader =
>>>> LoaderUtil.getThreadContextClassLoader();
>>>> final String path =
>>>> ConfigurationFactory.extractClassLoaderUriPath(configLocation);
>>>> final ConfigurationSource source = fromResource(path, loader);
>>>> if (source != null) {
>>>> return source;
>>>> }
>>>> }
>>>> if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing
>>>> error message thrown by uri.toURL()
>>>> ConfigurationFactory.LOGGER.error("File not found in file system
>>>> or classpath: {}", configLocation.toString());
>>>> return null;
>>>> }
>>>> try {
>>>> return new
>>>> ConfigurationSource(configLocation.toURL().openStream(),
>>>> configLocation.toURL());
>>>> } catch (final MalformedURLException ex) {
>>>> ConfigurationFactory.LOGGER.error("Invalid URL {}",
>>>> configLocation.toString(), ex);
>>>> } catch (final Exception ex) {
>>>> ConfigurationFactory.LOGGER.error("Unable to access {}",
>>>> configLocation.toString(), ex);
>>>> }
>>>> return null;
>>>> }
>>>> I should point out that the stack trace log you are seeing is from the
>>>> above code failing. If any of the above doesn’t work we then try to create
>>>> a ConfigurationSource using the following code where config is the value of
>>>> the property and loader is the ThreadContextClassLoader. So even with the
>>>> error that is shown it is still possible that the file might be found.
>>>>
>>>> protected ConfigurationSource getInputFromString(final String config,
>>>> final ClassLoader loader) {
>>>> try {
>>>> final URL url = new URL(config);
>>>> return new ConfigurationSource(url.openStream(),
>>>> FileUtils.fileFromUri(url.toURI()));
>>>> } catch (final Exception ex) {
>>>> final ConfigurationSource source =
>>>> ConfigurationSource.fromResource(config, loader);
>>>> if (source == null) {
>>>> try {
>>>> final File file = new File(config);
>>>> return new ConfigurationSource(new FileInputStream(file),
>>>> file);
>>>> } catch (final FileNotFoundException fnfe) {
>>>> // Ignore the exception
>>>> LOGGER.catching(Level.DEBUG, fnfe);
>>>> }
>>>> }
>>>> return source;
>>>> }
>>>> }
>>>> ConfigurationSource.fromResource() tries to locate the resource using
>>>> ClassLoader.getResource() and then constructs a ConfgurationSource if it
>>>> can find it. And if all else fails we just pass the string to the File
>>>> constructor and hope for the best.
>>>> As you can see we aren’t really manipulating the input string that was
>>>> provided to us, but we are trying any way we can to convert it into some
>>>> sort of file we can access. If you see something missing in this logic
>>>> please let us know.
>>>>
>>>> Ralph
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> On Jul 5, 2018, at 1:59 PM, Shawn Heisey <ap...@elyograg.org> wrote:
>>>>>
>>>>> On 7/5/2018 11:38 AM, Ralph Goers wrote:
>>>>>> I have updated the issue you referenced. From what I can tell this is
>>>> not an issue in Log4j. It is an issue with the way file urls work.
>>>>>
>>>>> Thanks for your attention.
>>>>>
>>>>> The startup script included with Solr versions before 7.4 (using log4j
>>>>> 1.2.x) also did not have // in the file: URI for the log4j.properties
>>>>> file, and it works on both Linux and Windows.
>>>>>
>>>>> Something else I found in the RFC you linked:
>>>>>
>>>>> The syntax given in Section 2 makes the entire authority component,
>>>>> including the double slashes "//", optional.
>>>>>
>>>>> Reading section 2, I didn't actually see that stated. Maybe it's
>>>>> something clarified by one of the other referenced RFCs. But if we take
>>>>> that statement at face value, it seems to be saying that a URI without
>>>>> // should work. It *does* work on Linux. On Windows, this:
>>>>>
>>>>> file:C:\path\to\stuff\log4j2.xml
>>>>>
>>>>> gets translated into this:
>>>>>
>>>>> file:/$CWD/file:C:/path/to/stuff/log4j2.xml
>>>>>
>>>>> Where $CWD is the current working directory. Even the "extra" URI added
>>>>> as a prefix doesn't have the // in it. If instead we use the following,
>>>>> it works as expected:
>>>>>
>>>>> file://C:\path\to\stuff\log4j2.xml
>>>>>
>>>>> If you're sure that there's nothing in log4j code that would result in
>>>>> the strange location, I'd be willing to accept that this problem is
>>>>> caused by Java or the OS and not log4j. The fact that this doesn't
>>>>> happen on Linux is even more reason to believe that. I don't know how
>>>>> likely it is that log4j contains code that behaves differently based on
>>>>> detected OS ... but I strongly believe that you'd want to avoid that if
>>>>> possible.
>>>>>
>>>>> I believe that we can safely add // to Solr's command script to solve
>>>>> this issue for our users, because the value should always be a full
>>>>> absolute path.
>>>>>
>>>>> But I would like to pursue the remaining question: When the RFC is
>>>>> fully and correctly evaluated, is a "file:" URI without "//" considered
>>>>> valid? If not, then that ends the discussion. If it is considered
>>>>> valid, then there's another question: Is it Java, log4j, or Windows that
>>>>> is causing the problem we've seen?
>>>>>
>>>>> Another question: What is the stance of the project on whether non-URI
>>>>> syntax for the log4j.configurationFile system property will be supported
>>>>> long-term? I can remember running into a problem with logging
>>>>> configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
>>>>> been java.util.logging) where the configuration wasn't found until I
>>>>> added "file:" to turn it into a URI. I did not use // in the URI. This
>>>>> is a line from the init script I wrote for Solr 4.x versions (when Solr
>>>>> did not include a startup script):
>>>>>
>>>>> LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
>>>>>
>>>>> Thanks,
>>>>> Shawn
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
So that is some weirdness with Java itself, and only on Windows.
Ralph
> On Jul 5, 2018, at 7:34 PM, Remko Popma <re...@gmail.com> wrote:
>
> I found that the problem can be reproduced with this:
>
> new File(“file:C:\\temp\\some.file”).toURI()
>
> If you print the above it shows:
>
> file:/C:/my/current/directory/file:C:/temp/some.file
>
>
> So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
>
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
>> On Jul 6, 2018, at 10:52, Gary Gregory <ga...@gmail.com> wrote:
>>
>> Can't URL contain commas?
>>
>> Gary
>>
>>> On Thu, Jul 5, 2018, 18:11 Ralph Goers <ra...@dslextreme.com> wrote:
>>>
>>> Here is what Log4j does:
>>>
>>> If the property is specified first see if it contains any commas, if so
>>> then there will be multiple configuration files, which essentially does
>>> what follows for each file. If not then try to convert it to a URI using
>>> the following code:
>>>
>>> public static URI toURI(final String path) {
>>> try {
>>> // Resolves absolute URI
>>> return new URI(path);
>>> } catch (final URISyntaxException e) {
>>> // A file path or a Apache Commons VFS URL might contain blanks.
>>> // A file path may start with a driver letter
>>> try {
>>> final URL url = new URL(path);
>>> return new URI(url.getProtocol(), url.getHost(),
>>> url.getPath(), null);
>>> } catch (MalformedURLException | URISyntaxException nestedEx) {
>>> return new File(path).toURI();
>>> }
>>> }
>>> }
>>>
>>> The URI is then converted to a ConfigurationSource using:
>>> public static ConfigurationSource fromUri(final URI configLocation) {
>>> final File configFile = FileUtils.fileFromUri(configLocation);
>>> if (configFile != null && configFile.exists() && configFile.canRead())
>>> {
>>> try {
>>> return new ConfigurationSource(new
>>> FileInputStream(configFile), configFile);
>>> } catch (final FileNotFoundException ex) {
>>> ConfigurationFactory.LOGGER.error("Cannot locate file {}",
>>> configLocation.getPath(), ex);
>>> }
>>> }
>>> if (ConfigurationFactory.isClassLoaderUri(configLocation)) {
>>> final ClassLoader loader =
>>> LoaderUtil.getThreadContextClassLoader();
>>> final String path =
>>> ConfigurationFactory.extractClassLoaderUriPath(configLocation);
>>> final ConfigurationSource source = fromResource(path, loader);
>>> if (source != null) {
>>> return source;
>>> }
>>> }
>>> if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing
>>> error message thrown by uri.toURL()
>>> ConfigurationFactory.LOGGER.error("File not found in file system
>>> or classpath: {}", configLocation.toString());
>>> return null;
>>> }
>>> try {
>>> return new
>>> ConfigurationSource(configLocation.toURL().openStream(),
>>> configLocation.toURL());
>>> } catch (final MalformedURLException ex) {
>>> ConfigurationFactory.LOGGER.error("Invalid URL {}",
>>> configLocation.toString(), ex);
>>> } catch (final Exception ex) {
>>> ConfigurationFactory.LOGGER.error("Unable to access {}",
>>> configLocation.toString(), ex);
>>> }
>>> return null;
>>> }
>>> I should point out that the stack trace log you are seeing is from the
>>> above code failing. If any of the above doesn’t work we then try to create
>>> a ConfigurationSource using the following code where config is the value of
>>> the property and loader is the ThreadContextClassLoader. So even with the
>>> error that is shown it is still possible that the file might be found.
>>>
>>> protected ConfigurationSource getInputFromString(final String config,
>>> final ClassLoader loader) {
>>> try {
>>> final URL url = new URL(config);
>>> return new ConfigurationSource(url.openStream(),
>>> FileUtils.fileFromUri(url.toURI()));
>>> } catch (final Exception ex) {
>>> final ConfigurationSource source =
>>> ConfigurationSource.fromResource(config, loader);
>>> if (source == null) {
>>> try {
>>> final File file = new File(config);
>>> return new ConfigurationSource(new FileInputStream(file),
>>> file);
>>> } catch (final FileNotFoundException fnfe) {
>>> // Ignore the exception
>>> LOGGER.catching(Level.DEBUG, fnfe);
>>> }
>>> }
>>> return source;
>>> }
>>> }
>>> ConfigurationSource.fromResource() tries to locate the resource using
>>> ClassLoader.getResource() and then constructs a ConfgurationSource if it
>>> can find it. And if all else fails we just pass the string to the File
>>> constructor and hope for the best.
>>> As you can see we aren’t really manipulating the input string that was
>>> provided to us, but we are trying any way we can to convert it into some
>>> sort of file we can access. If you see something missing in this logic
>>> please let us know.
>>>
>>> Ralph
>>>
>>>
>>>
>>>
>>>
>>>> On Jul 5, 2018, at 1:59 PM, Shawn Heisey <ap...@elyograg.org> wrote:
>>>>
>>>> On 7/5/2018 11:38 AM, Ralph Goers wrote:
>>>>> I have updated the issue you referenced. From what I can tell this is
>>> not an issue in Log4j. It is an issue with the way file urls work.
>>>>
>>>> Thanks for your attention.
>>>>
>>>> The startup script included with Solr versions before 7.4 (using log4j
>>>> 1.2.x) also did not have // in the file: URI for the log4j.properties
>>>> file, and it works on both Linux and Windows.
>>>>
>>>> Something else I found in the RFC you linked:
>>>>
>>>> The syntax given in Section 2 makes the entire authority component,
>>>> including the double slashes "//", optional.
>>>>
>>>> Reading section 2, I didn't actually see that stated. Maybe it's
>>>> something clarified by one of the other referenced RFCs. But if we take
>>>> that statement at face value, it seems to be saying that a URI without
>>>> // should work. It *does* work on Linux. On Windows, this:
>>>>
>>>> file:C:\path\to\stuff\log4j2.xml
>>>>
>>>> gets translated into this:
>>>>
>>>> file:/$CWD/file:C:/path/to/stuff/log4j2.xml
>>>>
>>>> Where $CWD is the current working directory. Even the "extra" URI added
>>>> as a prefix doesn't have the // in it. If instead we use the following,
>>>> it works as expected:
>>>>
>>>> file://C:\path\to\stuff\log4j2.xml
>>>>
>>>> If you're sure that there's nothing in log4j code that would result in
>>>> the strange location, I'd be willing to accept that this problem is
>>>> caused by Java or the OS and not log4j. The fact that this doesn't
>>>> happen on Linux is even more reason to believe that. I don't know how
>>>> likely it is that log4j contains code that behaves differently based on
>>>> detected OS ... but I strongly believe that you'd want to avoid that if
>>>> possible.
>>>>
>>>> I believe that we can safely add // to Solr's command script to solve
>>>> this issue for our users, because the value should always be a full
>>>> absolute path.
>>>>
>>>> But I would like to pursue the remaining question: When the RFC is
>>>> fully and correctly evaluated, is a "file:" URI without "//" considered
>>>> valid? If not, then that ends the discussion. If it is considered
>>>> valid, then there's another question: Is it Java, log4j, or Windows that
>>>> is causing the problem we've seen?
>>>>
>>>> Another question: What is the stance of the project on whether non-URI
>>>> syntax for the log4j.configurationFile system property will be supported
>>>> long-term? I can remember running into a problem with logging
>>>> configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
>>>> been java.util.logging) where the configuration wasn't found until I
>>>> added "file:" to turn it into a URI. I did not use // in the URI. This
>>>> is a line from the init script I wrote for Solr 4.x versions (when Solr
>>>> did not include a startup script):
>>>>
>>>> LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
>>>>
>>>> Thanks,
>>>> Shawn
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Remko Popma <re...@gmail.com>.
Shawn,
I think the safest option is simply to remove the “file:” prefix since you found that works with log4j 2 on all operating systems.
Remko-
(Shameless plug) Every java main() method deserves http://picocli.info
> On Jul 7, 2018, at 3:26, Ralph Goers <ra...@dslextreme.com> wrote:
>
> Here is the entirety of the logic for Log4j 1
>
> try {
> url = new URL(configurationOptionStr);
> } catch (MalformedURLException ex) {
> // so, resource is not a URL:
> // attempt to get the resource from the class path
> url = Loader.getResource(configurationOptionStr);
> }
> The main difference I see is that Log4j 2 tries to create a URI and only tries to create a URL if creating the URI throws an exception.
>
> I’m all for switching to NIO2 if it provides an easier way to find the file from all the various places it could be.
>
>
> Ralph
>
>
>
>
>
>> On Jul 6, 2018, at 10:50 AM, Shawn Heisey <ap...@elyograg.org> wrote:
>>
>> On 7/5/2018 8:34 PM, Remko Popma wrote:
>>> I found that the problem can be reproduced with this:
>>>
>>> new File(“file:C:\\temp\\some.file”).toURI()
>>>
>>> If you print the above it shows:
>>>
>>> file:/C:/my/current/directory/file:C:/temp/some.file
>>>
>>>
>>> So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
>>
>> Thanks to everyone who has replied, the discussion is valuable to me.
>>
>> If I add //, it works with absolute paths on log4j2 when running on
>> Windows. I haven't checked Linux, but I suspect it would work there too.
>>
>> But the URI without // works on Linux in log4j2. I haven't tested, but
>> I think that I would be able to use a relative path on Linux with the
>> "file:" prefix.
>>
>> The file: URI without // works on both Linux AND Windows in log4j 1.x.
>> I can use relative paths with either OS when using log4j 1.x. Something
>> has changed from log4j 1.x to 2.x, something that works without problems
>> on Linux but breaks on Windows. I think it's been well demonstrated
>> that the problem is in Java, not log4j.
>>
>> For fixing the problem in Solr on Windows, I see two possibilities:
>>
>> One fix (which I know works) is to abandon the file: prefix entirely.
>> In the Solr startup script, the location is an absolute path. But I do
>> have some worries that this might break in a future version. In log4j
>> 1.x the "file:" prefix appears to be mandatory -- if I remove it from
>> the log4j.configuration system property, my logging configuration isn't
>> found. With log4j 2.x, the system property is different --
>> log4j.configurationFile instead of log4j.configuration ... which
>> suggests that URI syntax won't be required.
>>
>> The other fix is to add slashes after file: ... but I'm not sure whether
>> it should be two slashes or three slashes. Experiments with
>> Path#toUri() suggest that three slashes might be the preferred canonical
>> form, but I'd like to know for sure. Two slashes does appear to work
>> with log4j.
>>
>> Tangent: Has there been any desire in the project to abandon the File
>> object and switch to NIO2? Lucene made that plunge a while back. I've
>> heard that it's a much better API.
>>
>> Experiments with 'new URI(string)' seem to indicate that log4j (both 1.x
>> and 2.x) accepts URI variations that are not allowed by the URI object.
>> A prefix of "file://" with a Windows path isn't allowed -- it requires
>> "file:///" to work. Because the Windows command shell provides paths
>> with backlashes, it would be difficult to specify a completely valid URI
>> -- backslashes do not appear to be allowed in strict syntax.
>>
>> Thanks,
>> Shawn
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
Here is the entirety of the logic for Log4j 1
try {
url = new URL(configurationOptionStr);
} catch (MalformedURLException ex) {
// so, resource is not a URL:
// attempt to get the resource from the class path
url = Loader.getResource(configurationOptionStr);
}
The main difference I see is that Log4j 2 tries to create a URI and only tries to create a URL if creating the URI throws an exception.
I’m all for switching to NIO2 if it provides an easier way to find the file from all the various places it could be.
Ralph
> On Jul 6, 2018, at 10:50 AM, Shawn Heisey <ap...@elyograg.org> wrote:
>
> On 7/5/2018 8:34 PM, Remko Popma wrote:
>> I found that the problem can be reproduced with this:
>>
>> new File(“file:C:\\temp\\some.file”).toURI()
>>
>> If you print the above it shows:
>>
>> file:/C:/my/current/directory/file:C:/temp/some.file
>>
>>
>> So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
>
> Thanks to everyone who has replied, the discussion is valuable to me.
>
> If I add //, it works with absolute paths on log4j2 when running on
> Windows. I haven't checked Linux, but I suspect it would work there too.
>
> But the URI without // works on Linux in log4j2. I haven't tested, but
> I think that I would be able to use a relative path on Linux with the
> "file:" prefix.
>
> The file: URI without // works on both Linux AND Windows in log4j 1.x.
> I can use relative paths with either OS when using log4j 1.x. Something
> has changed from log4j 1.x to 2.x, something that works without problems
> on Linux but breaks on Windows. I think it's been well demonstrated
> that the problem is in Java, not log4j.
>
> For fixing the problem in Solr on Windows, I see two possibilities:
>
> One fix (which I know works) is to abandon the file: prefix entirely.
> In the Solr startup script, the location is an absolute path. But I do
> have some worries that this might break in a future version. In log4j
> 1.x the "file:" prefix appears to be mandatory -- if I remove it from
> the log4j.configuration system property, my logging configuration isn't
> found. With log4j 2.x, the system property is different --
> log4j.configurationFile instead of log4j.configuration ... which
> suggests that URI syntax won't be required.
>
> The other fix is to add slashes after file: ... but I'm not sure whether
> it should be two slashes or three slashes. Experiments with
> Path#toUri() suggest that three slashes might be the preferred canonical
> form, but I'd like to know for sure. Two slashes does appear to work
> with log4j.
>
> Tangent: Has there been any desire in the project to abandon the File
> object and switch to NIO2? Lucene made that plunge a while back. I've
> heard that it's a much better API.
>
> Experiments with 'new URI(string)' seem to indicate that log4j (both 1.x
> and 2.x) accepts URI variations that are not allowed by the URI object.
> A prefix of "file://" with a Windows path isn't allowed -- it requires
> "file:///" to work. Because the Windows command shell provides paths
> with backlashes, it would be difficult to specify a completely valid URI
> -- backslashes do not appear to be allowed in strict syntax.
>
> Thanks,
> Shawn
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
Re: Odd problem starting program with log4j2 on Windows
Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/5/2018 8:34 PM, Remko Popma wrote:
> I found that the problem can be reproduced with this:
>
> new File(“file:C:\\temp\\some.file”).toURI()
>
> If you print the above it shows:
>
> file:/C:/my/current/directory/file:C:/temp/some.file
>
>
> So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
Thanks to everyone who has replied, the discussion is valuable to me.
If I add //, it works with absolute paths on log4j2 when running on
Windows. I haven't checked Linux, but I suspect it would work there too.
But the URI without // works on Linux in log4j2. I haven't tested, but
I think that I would be able to use a relative path on Linux with the
"file:" prefix.
The file: URI without // works on both Linux AND Windows in log4j 1.x.
I can use relative paths with either OS when using log4j 1.x. Something
has changed from log4j 1.x to 2.x, something that works without problems
on Linux but breaks on Windows. I think it's been well demonstrated
that the problem is in Java, not log4j.
For fixing the problem in Solr on Windows, I see two possibilities:
One fix (which I know works) is to abandon the file: prefix entirely.
In the Solr startup script, the location is an absolute path. But I do
have some worries that this might break in a future version. In log4j
1.x the "file:" prefix appears to be mandatory -- if I remove it from
the log4j.configuration system property, my logging configuration isn't
found. With log4j 2.x, the system property is different --
log4j.configurationFile instead of log4j.configuration ... which
suggests that URI syntax won't be required.
The other fix is to add slashes after file: ... but I'm not sure whether
it should be two slashes or three slashes. Experiments with
Path#toUri() suggest that three slashes might be the preferred canonical
form, but I'd like to know for sure. Two slashes does appear to work
with log4j.
Tangent: Has there been any desire in the project to abandon the File
object and switch to NIO2? Lucene made that plunge a while back. I've
heard that it's a much better API.
Experiments with 'new URI(string)' seem to indicate that log4j (both 1.x
and 2.x) accepts URI variations that are not allowed by the URI object.
A prefix of "file://" with a Windows path isn't allowed -- it requires
"file:///" to work. Because the Windows command shell provides paths
with backlashes, it would be difficult to specify a completely valid URI
-- backslashes do not appear to be allowed in strict syntax.
Thanks,
Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Remko Popma <re...@gmail.com>.
I found that the problem can be reproduced with this:
new File(“file:C:\\temp\\some.file”).toURI()
If you print the above it shows:
file:/C:/my/current/directory/file:C:/temp/some.file
So, the configuration should not prefix the path with “file:”, but with “file:/“ (slash after the colon).
(Shameless plug) Every java main() method deserves http://picocli.info
> On Jul 6, 2018, at 10:52, Gary Gregory <ga...@gmail.com> wrote:
>
> Can't URL contain commas?
>
> Gary
>
>> On Thu, Jul 5, 2018, 18:11 Ralph Goers <ra...@dslextreme.com> wrote:
>>
>> Here is what Log4j does:
>>
>> If the property is specified first see if it contains any commas, if so
>> then there will be multiple configuration files, which essentially does
>> what follows for each file. If not then try to convert it to a URI using
>> the following code:
>>
>> public static URI toURI(final String path) {
>> try {
>> // Resolves absolute URI
>> return new URI(path);
>> } catch (final URISyntaxException e) {
>> // A file path or a Apache Commons VFS URL might contain blanks.
>> // A file path may start with a driver letter
>> try {
>> final URL url = new URL(path);
>> return new URI(url.getProtocol(), url.getHost(),
>> url.getPath(), null);
>> } catch (MalformedURLException | URISyntaxException nestedEx) {
>> return new File(path).toURI();
>> }
>> }
>> }
>>
>> The URI is then converted to a ConfigurationSource using:
>> public static ConfigurationSource fromUri(final URI configLocation) {
>> final File configFile = FileUtils.fileFromUri(configLocation);
>> if (configFile != null && configFile.exists() && configFile.canRead())
>> {
>> try {
>> return new ConfigurationSource(new
>> FileInputStream(configFile), configFile);
>> } catch (final FileNotFoundException ex) {
>> ConfigurationFactory.LOGGER.error("Cannot locate file {}",
>> configLocation.getPath(), ex);
>> }
>> }
>> if (ConfigurationFactory.isClassLoaderUri(configLocation)) {
>> final ClassLoader loader =
>> LoaderUtil.getThreadContextClassLoader();
>> final String path =
>> ConfigurationFactory.extractClassLoaderUriPath(configLocation);
>> final ConfigurationSource source = fromResource(path, loader);
>> if (source != null) {
>> return source;
>> }
>> }
>> if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing
>> error message thrown by uri.toURL()
>> ConfigurationFactory.LOGGER.error("File not found in file system
>> or classpath: {}", configLocation.toString());
>> return null;
>> }
>> try {
>> return new
>> ConfigurationSource(configLocation.toURL().openStream(),
>> configLocation.toURL());
>> } catch (final MalformedURLException ex) {
>> ConfigurationFactory.LOGGER.error("Invalid URL {}",
>> configLocation.toString(), ex);
>> } catch (final Exception ex) {
>> ConfigurationFactory.LOGGER.error("Unable to access {}",
>> configLocation.toString(), ex);
>> }
>> return null;
>> }
>> I should point out that the stack trace log you are seeing is from the
>> above code failing. If any of the above doesn’t work we then try to create
>> a ConfigurationSource using the following code where config is the value of
>> the property and loader is the ThreadContextClassLoader. So even with the
>> error that is shown it is still possible that the file might be found.
>>
>> protected ConfigurationSource getInputFromString(final String config,
>> final ClassLoader loader) {
>> try {
>> final URL url = new URL(config);
>> return new ConfigurationSource(url.openStream(),
>> FileUtils.fileFromUri(url.toURI()));
>> } catch (final Exception ex) {
>> final ConfigurationSource source =
>> ConfigurationSource.fromResource(config, loader);
>> if (source == null) {
>> try {
>> final File file = new File(config);
>> return new ConfigurationSource(new FileInputStream(file),
>> file);
>> } catch (final FileNotFoundException fnfe) {
>> // Ignore the exception
>> LOGGER.catching(Level.DEBUG, fnfe);
>> }
>> }
>> return source;
>> }
>> }
>> ConfigurationSource.fromResource() tries to locate the resource using
>> ClassLoader.getResource() and then constructs a ConfgurationSource if it
>> can find it. And if all else fails we just pass the string to the File
>> constructor and hope for the best.
>> As you can see we aren’t really manipulating the input string that was
>> provided to us, but we are trying any way we can to convert it into some
>> sort of file we can access. If you see something missing in this logic
>> please let us know.
>>
>> Ralph
>>
>>
>>
>>
>>
>>> On Jul 5, 2018, at 1:59 PM, Shawn Heisey <ap...@elyograg.org> wrote:
>>>
>>> On 7/5/2018 11:38 AM, Ralph Goers wrote:
>>>> I have updated the issue you referenced. From what I can tell this is
>> not an issue in Log4j. It is an issue with the way file urls work.
>>>
>>> Thanks for your attention.
>>>
>>> The startup script included with Solr versions before 7.4 (using log4j
>>> 1.2.x) also did not have // in the file: URI for the log4j.properties
>>> file, and it works on both Linux and Windows.
>>>
>>> Something else I found in the RFC you linked:
>>>
>>> The syntax given in Section 2 makes the entire authority component,
>>> including the double slashes "//", optional.
>>>
>>> Reading section 2, I didn't actually see that stated. Maybe it's
>>> something clarified by one of the other referenced RFCs. But if we take
>>> that statement at face value, it seems to be saying that a URI without
>>> // should work. It *does* work on Linux. On Windows, this:
>>>
>>> file:C:\path\to\stuff\log4j2.xml
>>>
>>> gets translated into this:
>>>
>>> file:/$CWD/file:C:/path/to/stuff/log4j2.xml
>>>
>>> Where $CWD is the current working directory. Even the "extra" URI added
>>> as a prefix doesn't have the // in it. If instead we use the following,
>>> it works as expected:
>>>
>>> file://C:\path\to\stuff\log4j2.xml
>>>
>>> If you're sure that there's nothing in log4j code that would result in
>>> the strange location, I'd be willing to accept that this problem is
>>> caused by Java or the OS and not log4j. The fact that this doesn't
>>> happen on Linux is even more reason to believe that. I don't know how
>>> likely it is that log4j contains code that behaves differently based on
>>> detected OS ... but I strongly believe that you'd want to avoid that if
>>> possible.
>>>
>>> I believe that we can safely add // to Solr's command script to solve
>>> this issue for our users, because the value should always be a full
>>> absolute path.
>>>
>>> But I would like to pursue the remaining question: When the RFC is
>>> fully and correctly evaluated, is a "file:" URI without "//" considered
>>> valid? If not, then that ends the discussion. If it is considered
>>> valid, then there's another question: Is it Java, log4j, or Windows that
>>> is causing the problem we've seen?
>>>
>>> Another question: What is the stance of the project on whether non-URI
>>> syntax for the log4j.configurationFile system property will be supported
>>> long-term? I can remember running into a problem with logging
>>> configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
>>> been java.util.logging) where the configuration wasn't found until I
>>> added "file:" to turn it into a URI. I did not use // in the URI. This
>>> is a line from the init script I wrote for Solr 4.x versions (when Solr
>>> did not include a startup script):
>>>
>>> LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
>>>
>>> Thanks,
>>> Shawn
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Gary Gregory <ga...@gmail.com>.
Can't URL contain commas?
Gary
On Thu, Jul 5, 2018, 18:11 Ralph Goers <ra...@dslextreme.com> wrote:
> Here is what Log4j does:
>
> If the property is specified first see if it contains any commas, if so
> then there will be multiple configuration files, which essentially does
> what follows for each file. If not then try to convert it to a URI using
> the following code:
>
> public static URI toURI(final String path) {
> try {
> // Resolves absolute URI
> return new URI(path);
> } catch (final URISyntaxException e) {
> // A file path or a Apache Commons VFS URL might contain blanks.
> // A file path may start with a driver letter
> try {
> final URL url = new URL(path);
> return new URI(url.getProtocol(), url.getHost(),
> url.getPath(), null);
> } catch (MalformedURLException | URISyntaxException nestedEx) {
> return new File(path).toURI();
> }
> }
> }
>
> The URI is then converted to a ConfigurationSource using:
> public static ConfigurationSource fromUri(final URI configLocation) {
> final File configFile = FileUtils.fileFromUri(configLocation);
> if (configFile != null && configFile.exists() && configFile.canRead())
> {
> try {
> return new ConfigurationSource(new
> FileInputStream(configFile), configFile);
> } catch (final FileNotFoundException ex) {
> ConfigurationFactory.LOGGER.error("Cannot locate file {}",
> configLocation.getPath(), ex);
> }
> }
> if (ConfigurationFactory.isClassLoaderUri(configLocation)) {
> final ClassLoader loader =
> LoaderUtil.getThreadContextClassLoader();
> final String path =
> ConfigurationFactory.extractClassLoaderUriPath(configLocation);
> final ConfigurationSource source = fromResource(path, loader);
> if (source != null) {
> return source;
> }
> }
> if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing
> error message thrown by uri.toURL()
> ConfigurationFactory.LOGGER.error("File not found in file system
> or classpath: {}", configLocation.toString());
> return null;
> }
> try {
> return new
> ConfigurationSource(configLocation.toURL().openStream(),
> configLocation.toURL());
> } catch (final MalformedURLException ex) {
> ConfigurationFactory.LOGGER.error("Invalid URL {}",
> configLocation.toString(), ex);
> } catch (final Exception ex) {
> ConfigurationFactory.LOGGER.error("Unable to access {}",
> configLocation.toString(), ex);
> }
> return null;
> }
> I should point out that the stack trace log you are seeing is from the
> above code failing. If any of the above doesn’t work we then try to create
> a ConfigurationSource using the following code where config is the value of
> the property and loader is the ThreadContextClassLoader. So even with the
> error that is shown it is still possible that the file might be found.
>
> protected ConfigurationSource getInputFromString(final String config,
> final ClassLoader loader) {
> try {
> final URL url = new URL(config);
> return new ConfigurationSource(url.openStream(),
> FileUtils.fileFromUri(url.toURI()));
> } catch (final Exception ex) {
> final ConfigurationSource source =
> ConfigurationSource.fromResource(config, loader);
> if (source == null) {
> try {
> final File file = new File(config);
> return new ConfigurationSource(new FileInputStream(file),
> file);
> } catch (final FileNotFoundException fnfe) {
> // Ignore the exception
> LOGGER.catching(Level.DEBUG, fnfe);
> }
> }
> return source;
> }
> }
> ConfigurationSource.fromResource() tries to locate the resource using
> ClassLoader.getResource() and then constructs a ConfgurationSource if it
> can find it. And if all else fails we just pass the string to the File
> constructor and hope for the best.
> As you can see we aren’t really manipulating the input string that was
> provided to us, but we are trying any way we can to convert it into some
> sort of file we can access. If you see something missing in this logic
> please let us know.
>
> Ralph
>
>
>
>
>
> > On Jul 5, 2018, at 1:59 PM, Shawn Heisey <ap...@elyograg.org> wrote:
> >
> > On 7/5/2018 11:38 AM, Ralph Goers wrote:
> >> I have updated the issue you referenced. From what I can tell this is
> not an issue in Log4j. It is an issue with the way file urls work.
> >
> > Thanks for your attention.
> >
> > The startup script included with Solr versions before 7.4 (using log4j
> > 1.2.x) also did not have // in the file: URI for the log4j.properties
> > file, and it works on both Linux and Windows.
> >
> > Something else I found in the RFC you linked:
> >
> > The syntax given in Section 2 makes the entire authority component,
> > including the double slashes "//", optional.
> >
> > Reading section 2, I didn't actually see that stated. Maybe it's
> > something clarified by one of the other referenced RFCs. But if we take
> > that statement at face value, it seems to be saying that a URI without
> > // should work. It *does* work on Linux. On Windows, this:
> >
> > file:C:\path\to\stuff\log4j2.xml
> >
> > gets translated into this:
> >
> > file:/$CWD/file:C:/path/to/stuff/log4j2.xml
> >
> > Where $CWD is the current working directory. Even the "extra" URI added
> > as a prefix doesn't have the // in it. If instead we use the following,
> > it works as expected:
> >
> > file://C:\path\to\stuff\log4j2.xml
> >
> > If you're sure that there's nothing in log4j code that would result in
> > the strange location, I'd be willing to accept that this problem is
> > caused by Java or the OS and not log4j. The fact that this doesn't
> > happen on Linux is even more reason to believe that. I don't know how
> > likely it is that log4j contains code that behaves differently based on
> > detected OS ... but I strongly believe that you'd want to avoid that if
> > possible.
> >
> > I believe that we can safely add // to Solr's command script to solve
> > this issue for our users, because the value should always be a full
> > absolute path.
> >
> > But I would like to pursue the remaining question: When the RFC is
> > fully and correctly evaluated, is a "file:" URI without "//" considered
> > valid? If not, then that ends the discussion. If it is considered
> > valid, then there's another question: Is it Java, log4j, or Windows that
> > is causing the problem we've seen?
> >
> > Another question: What is the stance of the project on whether non-URI
> > syntax for the log4j.configurationFile system property will be supported
> > long-term? I can remember running into a problem with logging
> > configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
> > been java.util.logging) where the configuration wasn't found until I
> > added "file:" to turn it into a URI. I did not use // in the URI. This
> > is a line from the init script I wrote for Solr 4.x versions (when Solr
> > did not include a startup script):
> >
> > LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
> >
> > Thanks,
> > Shawn
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
>
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
Here is what Log4j does:
If the property is specified first see if it contains any commas, if so then there will be multiple configuration files, which essentially does what follows for each file. If not then try to convert it to a URI using the following code:
public static URI toURI(final String path) {
try {
// Resolves absolute URI
return new URI(path);
} catch (final URISyntaxException e) {
// A file path or a Apache Commons VFS URL might contain blanks.
// A file path may start with a driver letter
try {
final URL url = new URL(path);
return new URI(url.getProtocol(), url.getHost(), url.getPath(), null);
} catch (MalformedURLException | URISyntaxException nestedEx) {
return new File(path).toURI();
}
}
}
The URI is then converted to a ConfigurationSource using:
public static ConfigurationSource fromUri(final URI configLocation) {
final File configFile = FileUtils.fileFromUri(configLocation);
if (configFile != null && configFile.exists() && configFile.canRead()) {
try {
return new ConfigurationSource(new FileInputStream(configFile), configFile);
} catch (final FileNotFoundException ex) {
ConfigurationFactory.LOGGER.error("Cannot locate file {}", configLocation.getPath(), ex);
}
}
if (ConfigurationFactory.isClassLoaderUri(configLocation)) {
final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
final String path = ConfigurationFactory.extractClassLoaderUriPath(configLocation);
final ConfigurationSource source = fromResource(path, loader);
if (source != null) {
return source;
}
}
if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing error message thrown by uri.toURL()
ConfigurationFactory.LOGGER.error("File not found in file system or classpath: {}", configLocation.toString());
return null;
}
try {
return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.toURL());
} catch (final MalformedURLException ex) {
ConfigurationFactory.LOGGER.error("Invalid URL {}", configLocation.toString(), ex);
} catch (final Exception ex) {
ConfigurationFactory.LOGGER.error("Unable to access {}", configLocation.toString(), ex);
}
return null;
}
I should point out that the stack trace log you are seeing is from the above code failing. If any of the above doesn’t work we then try to create a ConfigurationSource using the following code where config is the value of the property and loader is the ThreadContextClassLoader. So even with the error that is shown it is still possible that the file might be found.
protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) {
try {
final URL url = new URL(config);
return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI()));
} catch (final Exception ex) {
final ConfigurationSource source = ConfigurationSource.fromResource(config, loader);
if (source == null) {
try {
final File file = new File(config);
return new ConfigurationSource(new FileInputStream(file), file);
} catch (final FileNotFoundException fnfe) {
// Ignore the exception
LOGGER.catching(Level.DEBUG, fnfe);
}
}
return source;
}
}
ConfigurationSource.fromResource() tries to locate the resource using ClassLoader.getResource() and then constructs a ConfgurationSource if it can find it. And if all else fails we just pass the string to the File constructor and hope for the best.
As you can see we aren’t really manipulating the input string that was provided to us, but we are trying any way we can to convert it into some sort of file we can access. If you see something missing in this logic please let us know.
Ralph
> On Jul 5, 2018, at 1:59 PM, Shawn Heisey <ap...@elyograg.org> wrote:
>
> On 7/5/2018 11:38 AM, Ralph Goers wrote:
>> I have updated the issue you referenced. From what I can tell this is not an issue in Log4j. It is an issue with the way file urls work.
>
> Thanks for your attention.
>
> The startup script included with Solr versions before 7.4 (using log4j
> 1.2.x) also did not have // in the file: URI for the log4j.properties
> file, and it works on both Linux and Windows.
>
> Something else I found in the RFC you linked:
>
> The syntax given in Section 2 makes the entire authority component,
> including the double slashes "//", optional.
>
> Reading section 2, I didn't actually see that stated. Maybe it's
> something clarified by one of the other referenced RFCs. But if we take
> that statement at face value, it seems to be saying that a URI without
> // should work. It *does* work on Linux. On Windows, this:
>
> file:C:\path\to\stuff\log4j2.xml
>
> gets translated into this:
>
> file:/$CWD/file:C:/path/to/stuff/log4j2.xml
>
> Where $CWD is the current working directory. Even the "extra" URI added
> as a prefix doesn't have the // in it. If instead we use the following,
> it works as expected:
>
> file://C:\path\to\stuff\log4j2.xml
>
> If you're sure that there's nothing in log4j code that would result in
> the strange location, I'd be willing to accept that this problem is
> caused by Java or the OS and not log4j. The fact that this doesn't
> happen on Linux is even more reason to believe that. I don't know how
> likely it is that log4j contains code that behaves differently based on
> detected OS ... but I strongly believe that you'd want to avoid that if
> possible.
>
> I believe that we can safely add // to Solr's command script to solve
> this issue for our users, because the value should always be a full
> absolute path.
>
> But I would like to pursue the remaining question: When the RFC is
> fully and correctly evaluated, is a "file:" URI without "//" considered
> valid? If not, then that ends the discussion. If it is considered
> valid, then there's another question: Is it Java, log4j, or Windows that
> is causing the problem we've seen?
>
> Another question: What is the stance of the project on whether non-URI
> syntax for the log4j.configurationFile system property will be supported
> long-term? I can remember running into a problem with logging
> configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
> been java.util.logging) where the configuration wasn't found until I
> added "file:" to turn it into a URI. I did not use // in the URI. This
> is a line from the init script I wrote for Solr 4.x versions (when Solr
> did not include a startup script):
>
> LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
>
> Thanks,
> Shawn
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
Re: Odd problem starting program with log4j2 on Windows
Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/5/2018 11:38 AM, Ralph Goers wrote:
> I have updated the issue you referenced. From what I can tell this is not an issue in Log4j. It is an issue with the way file urls work.
Thanks for your attention.
The startup script included with Solr versions before 7.4 (using log4j
1.2.x) also did not have // in the file: URI for the log4j.properties
file, and it works on both Linux and Windows.
Something else I found in the RFC you linked:
The syntax given in Section 2 makes the entire authority component,
including the double slashes "//", optional.
Reading section 2, I didn't actually see that stated. Maybe it's
something clarified by one of the other referenced RFCs. But if we take
that statement at face value, it seems to be saying that a URI without
// should work. It *does* work on Linux. On Windows, this:
file:C:\path\to\stuff\log4j2.xml
gets translated into this:
file:/$CWD/file:C:/path/to/stuff/log4j2.xml
Where $CWD is the current working directory. Even the "extra" URI added
as a prefix doesn't have the // in it. If instead we use the following,
it works as expected:
file://C:\path\to\stuff\log4j2.xml
If you're sure that there's nothing in log4j code that would result in
the strange location, I'd be willing to accept that this problem is
caused by Java or the OS and not log4j. The fact that this doesn't
happen on Linux is even more reason to believe that. I don't know how
likely it is that log4j contains code that behaves differently based on
detected OS ... but I strongly believe that you'd want to avoid that if
possible.
I believe that we can safely add // to Solr's command script to solve
this issue for our users, because the value should always be a full
absolute path.
But I would like to pursue the remaining question: When the RFC is
fully and correctly evaluated, is a "file:" URI without "//" considered
valid? If not, then that ends the discussion. If it is considered
valid, then there's another question: Is it Java, log4j, or Windows that
is causing the problem we've seen?
Another question: What is the stance of the project on whether non-URI
syntax for the log4j.configurationFile system property will be supported
long-term? I can remember running into a problem with logging
configuration in the past (I *think* it was log4j 1.x, but it MIGHT have
been java.util.logging) where the configuration wasn't found until I
added "file:" to turn it into a URI. I did not use // in the URI. This
is a line from the init script I wrote for Solr 4.x versions (when Solr
did not include a startup script):
LOG_OPTS="-Dlog4j.configuration=file:etc/log4j.properties"
Thanks,
Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
I have updated the issue you referenced. From what I can tell this is not an issue in Log4j. It is an issue with the way file urls work.
Ralph
> On Jul 5, 2018, at 9:05 AM, Shawn Heisey <ap...@elyograg.org> wrote:
>
> On 7/3/2018 4:59 PM, Ralph Goers wrote:
>> Also - Since %DEFAULT_SERVER_DIR% doesn’t have a leading “/“ you might have to specify file:///.
>
> There is no leading / on Windows. An absolute path starts with "X:" there.
>
> I created an eclipse project and then copied the resulting source and binary files, plus the minimum required log4j jars, to a new location and made a batch file to illustrate the problem.
>
> To try it, extract the following zipfile, open a command prompt, cd to the root of the extracted files, and type "script\start".
>
> https://www.dropbox.com/s/fpe8bw4ebf5l2l3/log4j-demo-config-problem.zip?dl=0
>
> The current working directory gets added to the location in URI form. This is also what is happening with the Solr startup.
>
> We have an issue in Solr to track getting the problem fixed there:
>
> https://issues.apache.org/jira/browse/SOLR-12538
>
> If I change "file:" to "file://" that does seem to fix the problem, but only if the indicated path is absolute. So it works on the Solr startup (which is working with absolute paths), but fails in my recreation zipfile, which uses a relative path.
>
> We are using file: on Linux without the // and aren't having any problems. It seems to be a problem only on Windows.
>
> Thanks,
> Shawn
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/3/2018 4:59 PM, Ralph Goers wrote:
> Also - Since %DEFAULT_SERVER_DIR% doesn’t have a leading “/“ you might have to specify file:///.
There is no leading / on Windows. An absolute path starts with "X:" there.
I created an eclipse project and then copied the resulting source and
binary files, plus the minimum required log4j jars, to a new location
and made a batch file to illustrate the problem.
To try it, extract the following zipfile, open a command prompt, cd to
the root of the extracted files, and type "script\start".
https://www.dropbox.com/s/fpe8bw4ebf5l2l3/log4j-demo-config-problem.zip?dl=0
The current working directory gets added to the location in URI form.
This is also what is happening with the Solr startup.
We have an issue in Solr to track getting the problem fixed there:
https://issues.apache.org/jira/browse/SOLR-12538
If I change "file:" to "file://" that does seem to fix the problem, but
only if the indicated path is absolute. So it works on the Solr startup
(which is working with absolute paths), but fails in my recreation
zipfile, which uses a relative path.
We are using file: on Linux without the // and aren't having any
problems. It seems to be a problem only on Windows.
Thanks,
Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
Also - Since %DEFAULT_SERVER_DIR% doesn’t have a leading “/“ you might have to specify file:///.
Ralph
> On Jul 3, 2018, at 3:56 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>
> What do you get if you change the -D to log4j.configurationFile=“file://%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j2.xml”? A normal file protocol on Windows shouldl end up looking like file:///C:/path/to/file/file.txt.
>
> See https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ (just one of several links I found) to illustrate this.
>
> Ralph
>
>> On Jul 3, 2018, at 8:10 AM, Shawn Heisey <ap...@elyograg.org> wrote:
>>
>> I'm investigating a problem a user is having with starting the latest
>> release of Solr on Windows. This release is the first one we've made
>> after upgrading log4j from 1.2.x to 2.11.0.
>>
>> I have double-checked that the script starts the program with this
>> commandline option:
>>
>> -Dlog4j.configurationFile="file:C:\Users\sheisey\Downloads\solr-7.4.0\server\scripts\cloud-scripts\log4j2.xml"
>>
>> This is what's actually in the .cmd file ... I used the 'echo' command
>> to verify what the full commandline expands to:
>>
>> -Dlog4j.configurationFile="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j2.xml"
>>
>> An exception is sent to stdout, which I will provide at the end of this
>> message.
>>
>> In the exception, you may notice that the path it says it can't find has
>> TWO "file:" elements in it, and two paths complete with "C:\" in them.
>> The value of DEFAULT_SERVER_DIR is
>> C:\Users\sheisey\Downloads\solr-7.4.0\server ... which is what's before
>> the second "file:" in the exception, with the backslashes converted to
>> forward slashes. Unless something is going very wrong with the windows
>> command script language so that the commandline isn't actually what I've
>> double-checked it to be, it looks like a problem in log4j ... one that
>> might only exist on Windows.
>>
>> I'm running this on Windows 7 enterprise edition, the user on the Solr
>> mailing list is running it on Windows 10 enterprise edition and running
>> into the same problem.
>>
>> If I remove the "file:" prefix from the value assigned to the system
>> property, so that it is a bare Windows path, everything works properly.
>> This workaround was mentioned by the user on the Solr mailing list.
>>
>> The same thing on Linux appears to work correctly. This is the
>> commandline option that ends up being used there:
>>
>> -Dlog4j.configurationFile=file:/index/src/solr-7.4.0/server/scripts/cloud-scripts/log4j2.xml
>>
>> Here's the exception that I get on Windows:
>>
>> ERROR StatusLogger Unable to access
>> file:/C:/Users/sheisey/Downloads/solr-7.4.0/server/file:C:/Users/sheisey/Downloads/solr-7.4.0/server/scripts/cloud-scripts/log4j2.xml
>> java.io.FileNotFoundException:
>> C:\Users\sheisey\Downloads\solr-7.4.0\server\file:C:\Users\sheisey\Downloads\solr-7.4.0\server\scripts\cloud-scripts\log4j2.xml
>> (The filename, directory name, or volume label syntax is incorrect)
>> at java.io.FileInputStream.open0(Native Method)
>> at java.io.FileInputStream.open(FileInputStream.java:195)
>> at java.io.FileInputStream.<init>(FileInputStream.java:138)
>> at java.io.FileInputStream.<init>(FileInputStream.java:93)
>> at
>> sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
>> at
>> sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
>> at java.net.URL.openStream(URL.java:1045)
>> at
>> org.apache.logging.log4j.core.config.ConfigurationSource.fromUri(ConfigurationSource.java:247)
>> at
>> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:404)
>> at
>> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:346)
>> at
>> org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:260)
>> at
>> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:615)
>> at
>> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
>> at
>> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
>> at
>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
>> at
>> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
>> at
>> org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
>> at
>> org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
>> at
>> org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
>> at
>> org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
>> at
>> org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
>> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
>> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
>> at org.apache.solr.util.SolrCLI.<clinit>(SolrCLI.java:228)
>>
>> Is there any other information I can provide? You can download Solr at
>> http://lucene.apache.org/solr if you need to reproduce and investigate
>> the scripting that comes with it.
>>
>> Thanks,
>> Shawn
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Ralph Goers <ra...@dslextreme.com>.
What do you get if you change the -D to log4j.configurationFile=“file://%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j2.xml”? A normal file protocol on Windows shouldl end up looking like file:///C:/path/to/file/file.txt.
See https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ (just one of several links I found) to illustrate this.
Ralph
> On Jul 3, 2018, at 8:10 AM, Shawn Heisey <ap...@elyograg.org> wrote:
>
> I'm investigating a problem a user is having with starting the latest
> release of Solr on Windows. This release is the first one we've made
> after upgrading log4j from 1.2.x to 2.11.0.
>
> I have double-checked that the script starts the program with this
> commandline option:
>
> -Dlog4j.configurationFile="file:C:\Users\sheisey\Downloads\solr-7.4.0\server\scripts\cloud-scripts\log4j2.xml"
>
> This is what's actually in the .cmd file ... I used the 'echo' command
> to verify what the full commandline expands to:
>
> -Dlog4j.configurationFile="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j2.xml"
>
> An exception is sent to stdout, which I will provide at the end of this
> message.
>
> In the exception, you may notice that the path it says it can't find has
> TWO "file:" elements in it, and two paths complete with "C:\" in them.
> The value of DEFAULT_SERVER_DIR is
> C:\Users\sheisey\Downloads\solr-7.4.0\server ... which is what's before
> the second "file:" in the exception, with the backslashes converted to
> forward slashes. Unless something is going very wrong with the windows
> command script language so that the commandline isn't actually what I've
> double-checked it to be, it looks like a problem in log4j ... one that
> might only exist on Windows.
>
> I'm running this on Windows 7 enterprise edition, the user on the Solr
> mailing list is running it on Windows 10 enterprise edition and running
> into the same problem.
>
> If I remove the "file:" prefix from the value assigned to the system
> property, so that it is a bare Windows path, everything works properly.
> This workaround was mentioned by the user on the Solr mailing list.
>
> The same thing on Linux appears to work correctly. This is the
> commandline option that ends up being used there:
>
> -Dlog4j.configurationFile=file:/index/src/solr-7.4.0/server/scripts/cloud-scripts/log4j2.xml
>
> Here's the exception that I get on Windows:
>
> ERROR StatusLogger Unable to access
> file:/C:/Users/sheisey/Downloads/solr-7.4.0/server/file:C:/Users/sheisey/Downloads/solr-7.4.0/server/scripts/cloud-scripts/log4j2.xml
> java.io.FileNotFoundException:
> C:\Users\sheisey\Downloads\solr-7.4.0\server\file:C:\Users\sheisey\Downloads\solr-7.4.0\server\scripts\cloud-scripts\log4j2.xml
> (The filename, directory name, or volume label syntax is incorrect)
> at java.io.FileInputStream.open0(Native Method)
> at java.io.FileInputStream.open(FileInputStream.java:195)
> at java.io.FileInputStream.<init>(FileInputStream.java:138)
> at java.io.FileInputStream.<init>(FileInputStream.java:93)
> at
> sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
> at
> sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
> at java.net.URL.openStream(URL.java:1045)
> at
> org.apache.logging.log4j.core.config.ConfigurationSource.fromUri(ConfigurationSource.java:247)
> at
> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:404)
> at
> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:346)
> at
> org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:260)
> at
> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:615)
> at
> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
> at
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
> at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
> at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
> at
> org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
> at
> org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
> at
> org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
> at
> org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
> at
> org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
> at org.apache.solr.util.SolrCLI.<clinit>(SolrCLI.java:228)
>
> Is there any other information I can provide? You can download Solr at
> http://lucene.apache.org/solr if you need to reproduce and investigate
> the scripting that comes with it.
>
> Thanks,
> Shawn
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Odd problem starting program with log4j2 on Windows
Posted by Remko Popma <re...@gmail.com>.
Hi Shawn,
Congrats with the Solr release and thanks for upgrading to log4j 2.
What you describe sounds very odd indeed!
If this is really a log4j issue, it should be possible to boil it down to a small Hello World-type project with a starter .bat file that demonstrates the issue.
Will you be able to provide this?
Kind regards,
Remko
(Shameless plug) Every java main() method deserves http://picocli.info
> On Jul 4, 2018, at 0:10, Shawn Heisey <ap...@elyograg.org> wrote:
>
> Dlog4j
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org