SimpleLog Logger and simplelog.properties File

Q

How to use SimpleLog Logger and simplelog.properties File?

✍: FYIcenter.com

A

The suggested way to use the SimpleLog Logger and simplelog.properties File is to do the following:

1.Create commons-logging.properties file with one entry:

# commons-logging.properties
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

2.Create simplelog.properties file:

# simplelog.properties
# Copyright (c) 2016 FYIcenter.com

# Show timestampe in the log
org.apache.commons.logging.simplelog.showdatetime=true

# Use the format for timestamp
org.apache.commons.logging.simplelog.dateTimeFormat=yyyy-MM-dd'T'HH:mm:ss.SSSZ

# Show logger instance name
org.apache.commons.logging.simplelog.showShortLogname=true

# Set level to "trace" on "MyLogging" instance
org.apache.commons.logging.simplelog.log.MyLogging=trace

# Set level to "warn" on all other log instances
org.apache.commons.logging.simplelog.defaultlog=warn

3. Run the HelloCommonsLogging example code with both properties files in the current folder, which is included in the class path:

C:\fyicenter>java -cp .;C:\local\commons-logging-1.2\commons-logging-1.2.jar
   HelloCommonsLogging
   
Log class: org.apache.commons.logging.impl.SimpleLog
2016-11-13T22:57:01.895-0500 [FATAL] MyLogging - Hello - fatal
2016-11-13T22:57:01.895-0500 [ERROR] MyLogging - Hello - error
2016-11-13T22:57:01.895-0500 [WARN] MyLogging - Hello - warn
2016-11-13T22:57:01.895-0500 [INFO] MyLogging - Hello - info
2016-11-13T22:57:01.895-0500 [DEBUG] MyLogging - Hello - debug
2016-11-13T22:57:01.895-0500 [TRACE] MyLogging - Hello - trace

 

Using commons-logging.jar in Java Code

⇒⇒FAQ for Apache commons-logging.jar

2016-11-16, 773👍, 0💬