java最簡單實現Log列印和生成日誌檔案

2021-09-08 05:32:13 字數 1063 閱讀 4806

導包

配置log4j

1.在src根目錄下建立乙個log4j.properties檔案。

檔案全部內容如下:

log4j.rootlogger=console,stdout,logfile

#stdout控制器

#輸出格式

#檔案路徑輸出

log日誌檔案輸出路徑可以改,我寫的是d:/keyservice.log。

**中使用:

1.improt包

import

org.apache.commons.logging.log;

import org.apache.commons.logging.logfactory;

2.宣告定義log

public

static log log = logfactory.getlog(你當前的類名.class);

3.使用log

比如:

package

example;

import

org.apache.commons.logging.log;

import

org.apache.commons.logging.logfactory;

public

class

helloworld

}

列印:

2018-05-10 10:46:29,566 info [example.helloworld]:10 - this

is info:sdibt

2018-05-10 10:46:29,566 error [example.helloworld]:11 - this

is error:sdibt

2018-05-10 10:46:29,566 debug [example.helloworld]:12 - this

is debug:sdibt

process finished with exit code 0

找到你配置的列印日誌檔案的目錄。就發現多了乙個輸出的log日誌檔案。

可變引數實現log列印

實現步驟如下 函式原型中使用省略號 函式定義中建立乙個va list變數 3.初始化va list變數 4.訪問引數列表 5.完成清理工作 上述步驟的實現需要使用到四個巨集 va list va start va list,arg va arg va list,type va end va list...

Log4j 最簡單內容

設定 log4j.rootlogger debug,stdout,d,e 輸出資訊到控制抬 輸出debug 級別以上的日誌到 e logs error.log 輸出error 級別以上的日誌到 e logs error.log import org.apache.log4j.logger impor...

最簡單的IdentityServer實現 Api

建立asp.net core web api專案identityserver.easydemo.api 2引用identityserver4.accesstokenvalidation 3新增介面檔案identitycontroller.cs,用於測試授權 如果你直接訪問http localhost...