(一) 下載jar包
GitHub鏈接:https://github.com/1160700306/tools/blob/master/log4j-1.2.17.jar
(現在官網上說要使用 log4j-api-2.x 和 the log4j-core-2.x jar, 但是試了不行, 所以還是用以前的包)
(二)新建一個項目Log, 放入jar包
右鍵項目, properties
Java Build Path-->Add External JARs
找到剛才jar包的位置, 打開即可
(三)將log4j.properties放入src文件夾中
這個倉庫https://github.com/1160700306/tools中有示例,可以自己改格式
(四)示例代碼及運行結果: