title: Log4J: can I enable/disable logging from a class at runtime?
body: <p>Sometimes logging needs to be enabled/disabled at runtime only during a specific phase of the execution of a code (e.g. for debugging purposes).
  Now, I use Java and Log4J to debug. This is my <code>log4j.properties</code> file:</p>
  
  <pre><code># Define the root logger with appender file
  log = /Users/Admin/Documents/log4j
  log4j.rootLogger = DEBUG, stdout, file
  
  #Logging for class Solution in package org.solver will be disabled
  log4j.category.org.solver.Solution = OFF, stdout, file
  
  # Define the file Console appender
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  
  # Define the file file appender
  log4j.appender.file=org.apache.log4j.FileAppender
  log4j.appender.file.File=${log}/log.out
  
  # Define the layout for file appender
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.conversionPattern=%m%n
  </code></pre>
  
  <p>As you may see, I log both on a file and on the console output.</p>
  
  <p>Now, suppose that I have a class <code>X</code> from package <code>foo</code>. How can I enable and disable the logging at runtime? <a href="https://stackoverflow.com/a/16380860/1983997">Here</a> I found a possible answer, but an example would be really appreciated.</p>