title: External logging configuration with Spring Cloud Config
body: <p><br>
  I just experienced Spring Cloud Config to have some configuration files outside of my projects. I followed the instructions to set up a client and a server (linked to a git) and it worked great !<br> 
  Basically I have different application.yml for each profile I have and inside these files there is a server port property and also an URL to the logging config file (one log4j2.yml per profile) which is also on my git repository.
  Without authentication it works well: the client asks the server for the application.yml file which matches its profile. Then, the server finds the file and return to the client the port and the log4j2 config file.<br> I have what I want which is a different level of logging depending on the client's profile.<br>
  When I set up the authentication with spring-security (with the default username and a simple password) the client recovers the port but when it tries to acess to the log4j2 config file, the server returns a 401 error saying that the client isn't authorized to access this file.<br> This might be due to the client not knowing the credentials to access the file inside the application.yml and I don't know if this is possible to insert credentials in the logging.config property</p>
  
  <p>I tried something like this but it's not working as well :</p>
  
  <pre><code>logging:
   config: http://user:password@localhost:8888/....../log4j2.yml
  </code></pre>
  
  <p>There might be an alternative which consists in saying to the server to ignore the security when the URL is that file but if one day I must have authentication to access it, I won't be able to do it.</p>
  
  <p>There's my files:</p>
  
  <p><strong>GIT</strong></p>
  
  <p>application-dev.yml</p>
  
  <pre><code>server:
   port: 55556
  
  logging:
   config: http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml
  </code></pre>
  
  <p><strong>CLIENT</strong></p>
  
  <p>boostrap.yml</p>
  
  <pre><code>spring:
    application:
      name: ConfigExtClient
    profiles:
      active: dev
    cloud:
      config:
        uri: http://localhost:8888
        username: user
        password: foo
  </code></pre>
  
  <p>Dependencies (pom.xml)</p>
  
  <pre><code>&lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.3.1.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;
              &lt;version&gt;1.1.0.M4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-dataformat-yaml&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
      &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>SERVER</strong></p>
  
  <p>application.yml</p>
  
  <pre><code>server:
    port: 8888
  
  spring:
    cloud:
      config:
        server:
          git:
            uri: URLtoGit
  
  security:
    user:
      name: user
      password: foo
  </code></pre>
  
  <p>bootstrap.yml</p>
  
  <pre><code>spring:
    application:
      name: ConfigExtServer
  </code></pre>
  
  <p>dependencies (pom.xml)</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.3.1.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-autoconfigure&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;spring-cloud-config-server&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.M4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-dataformat-yaml&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt; 
  </code></pre>
  
  <p><strong>ERROR</strong></p>
  
  <pre><code>Logging config file location 'http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml' cannot be opened and will be ignored
  </code></pre>
  
  <p>I tracked the error and it appears in the <em>PropertySourceBootstrapConfiguration</em> class in <em>reinitializeLoggingSystem</em> :</p>
  
  <pre><code>try {
              ResourceUtils.getURL(logConfig).openStream().close();
              system.initialize(new LoggingInitializationContext(environment),
                      logConfig, logFile);
          }
          catch (Exception ex) {
              PropertySourceBootstrapConfiguration.logger
                      .warn("Logging config file location '" + logConfig
                              + "' cannot be opened and will be ignored");
          }
  </code></pre>
  
  <p>It goes into catch and the exception is : </p>
  
  <pre><code>Server returned HTTP response code: 401 for URL: http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml
  </code></pre>
  
  <p>Thank you in advance for your help,<br>
  Romain</p>