Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Tony has provided an excellent answer here after I posted the question.</p> <p><a href="http://old.nabble.com/Enable-Debugging-Mode-Programmatically--td32961424.html" rel="nofollow">http://old.nabble.com/Enable-Debugging-Mode-Programmatically--td32961424.html</a></p> <p>This is very helpful when you are trying to figure out why LogBack doesn't work in certain cases. I opted to use the first way for my initialization code.</p> <p>Keep in mind that this is when you choose not to use a config file like in my kind of use case.</p> <hr> <p>From: tony19</p> <p>There are a couple ways:</p> <p>1) Use StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext)</p> <p>OR</p> <p>2) Load hard-coded string of configuration XML w/configuration.debug set to 'true':</p> <pre><code>static final String LOGBACK_XML = "&lt;configuration debug='true'&gt;" + " &lt;appender name='FILE' class='ch.qos.logback.core.RollingFileAppender'&gt;" + " &lt;file&gt;foo.log&lt;/file&gt;" + " &lt;append&gt;true&lt;/append&gt;" + " &lt;encoder&gt;" + " &lt;pattern&gt;%-4relative [%thread] %-5level %logger{35} - %msg%n&lt;/pattern&gt;" + " &lt;/encoder&gt;" + " &lt;/appender&gt;" + " &lt;root level='INFO'&gt;" + " &lt;appender-ref ref='FILE' /&gt;" + " &lt;/root&gt;" + "&lt;/configuration&gt;" ; static public void configLogback() { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(new ByteArrayInputStream(LOGBACK_XML.getBytes())); } catch (JoranException je) { je.printStackTrace(); } // you can also print the errors/warning explicitly (instead of debug='true' in xml) //StatusPrinter.printInCaseOfErrorsOrWarnings(lc); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload