gethのlogをms単位で取得する方法

やりたいこと:

今回は、gethのlogにおいて、ミリセカンド単位まで時間を表示させたい。

 

アプローチ:

logの時間はTimeFormatという変数で設定されている。

これは、geth, azureの設定ファイルで go言語で以下のように設定されているものだ。

go-ethereum/vendor/github.com/Azure/go-autorest/autorest/date/time.go

https://github.com/ethereum/go-ethereum/blob/master/vendor/github.com/Azure/go-autorest/autorest/date/time.go

この書式に基づいて、logのフォーマットを決めている箇所を編集すれば良い。

 

0: 編集するコード:

go-ethereum/log/format.go

https://github.com/ethereum/go-ethereum/blob/3991745c5f72033bdefb1ca5931f48857d8d9973/log/format.go

 

1: 編集箇所:

const (

timeFormat     = "2006-01-02T15:04:05-0700"

termTimeFormat = "01-02|15:04:05"

floatFormat    = 'f'

termMsgJust    = 40

)

 

2: 編集

timeFormat     = "2006-01-02T15:04:05.000-0700"

// timeFormat     = "2006-01-02T15:04:05-0700"

termTimeFormat = "01-02|15:04:05.000" 

// termTimeFormat = "01-02|15:04:05"

*...ミリセカンド以下の単位を表示したい場合は、小数点以下の0を増やしていけば良い。

 

3: ビルド

➜ go-ethereum git:(master) ✗ make geth

 

4: 結果

INFO [01-03|14:52:37.800] --
INFO [01-03|14:52:37.801] --