title: Logback with Spring Boot - programatically change configuration at runtime to add Syslog Appender
body: <p>I am building an application (Spring Boot 1.4.2) where i would like to offer an administrator the option to enable syslog but i want to avoid him/her having to manually edit any config files - in this case <code>logstash-spring.xml</code>.
  Therefore i am trying to understand how i can achieve using a <code>logback-spring.xml</code> file as a baseline (e.g. define file based log options, levels etc. - settings i dont want the administrator to change) and on top of that provide a functionality at runtime where an administrator can add or change a syslog appender.</p>
  
  <p>I have listed what i see as requirements:</p>
  
  <ol>
  <li>The changes made to the Logger should be persisted after the Spring Boot application is restarted.</li>
  <li>Ideally the syslog server info (name, port) are kept in my persistence layer (H2, hibernate) but i am not sure if that is possible as i guess the logging framework is being injected prior to my persistence layer?</li>
  <li>The syslog appender that i want to add should be referenced by root logger so that all the packages i have configured logging for would go to syslog (not sure if this is just "how it works per default")</li>
  </ol>
  
  <p>Also i dont know if i could simply treat <code>logback-spring.xml</code> as a regular XML object and use for example JAXB to manipulate that file and use the <a href="http://logback.qos.ch/manual/configuration.html#autoScan" rel="nofollow noreferrer">autoscan</a> feature of Logback to simply read in the new changes?</p>
  
  <p>I have played around with defining a <code>Logger</code> <code>@Bean</code>:</p>
  
  <pre><code>@Bean
  public Logger logger() {
      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
      // excluded implementation
  }
  </code></pre>
  
  <p>This is being picked up by Spring Boot but that brings me to the 2 items i have listed above that i dont know how or where i would store the syslog server information the administrator would provide.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I wrote the following which meets the 3 requirements above however i would appreciate any feedback on the actual implementation as i am very new to Spring and Java.</p>
  
  <p><a href="https://github.com/rsjorslev/spring-boot-logback-syslog/" rel="nofollow noreferrer">GitHub repository with implementation - spring-boot-logback-syslog</a></p>