Java – what is logging and how is Apache commons logging used?
What information does the web application server want to record and why?
as far as I am concerned
org.apache.commons.logging.Log
It is an interface that abstracts the functions provided by other logging classes. It is also applicable to the interface LogFactory
The code I want to know is –
Log auditLogger = LogFactory.getLog(someString);
How is string somestring used to identify the LogFactory to be generated? How to view the implementation of log and LogFactory classes in use?
Solution
This string is an arbitrary identifier that we can use to redirect or filter log output A common method is to use classname, for example,
Log auditLogger = LogFactory.getLog(MyCurrentClass.class);
As you said, commons logging is an appearance. If no other log library is provided, it defaults to Java util. logging. I suggest putting a log implementation in the classpath, such as log4j, logback or slf4j
Suppose you put, for example, log4j there, you can use the configuration file log4j XML controls logging output, for example:
<?xml version="1.0" encoding="UTF-8"?> <log4j:configuration> <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> ..... </appender> <!-- Send debug information from "com.company.MyCurrentClass" to CONSOLE --> <logger name="com.company.MyCurrentClass"> <level value="DEBUG"/> <appender-ref ref="CONSOLE"/> </logger> </log4j:configuration>