import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyClass { private static final Log log = LogFactory.getLog(MyClass.class); public void doSomething() { log.info("doing something"); } }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyClass { private static final Log log = LogFactory.getLog(MyClass.class); public void doSomething(int a, String b) { log.info("doing something with a={} and b={}", a, b); } }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyClass { private static final Log log = LogFactory.getLog(MyClass.class); public void doSomething() { log.info("doing something"); } }
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.PropertyConfigurator; import java.util.Properties; public class MyApp { public static void main(String[] args) { Properties props = new Properties(); props.load(new FileInputStream("mylog4j.properties")); PropertyConfigurator.configure(props); MyClass myClass = new MyClass(); myClass.doSomething(); } }In this code, we create a Properties object that holds the configuration for the "log4j" logging framework, then we call `PropertyConfigurator.configure` to set the configuration. Then we create an instance of `MyClass` and call its `doSomething` method, which should log the "info" message to the configured logging framework. Overall, the org.apache.commons.logging package provides a simple but powerful logging interface that can be used across a variety of Java applications.