1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

log4j2のJSONLayoutで人間向けのタイムスタンプを出力する

Last updated at Posted at 2019-07-17

log4j2のJSONLayoutを使うと出力日時をエポック秒で出力してくれる。

log.json
{
	"instant": {
		"epochSecond": 1563403242,
		"nanoOfSecond": 895000000
	}
}

人間ごときにエポック秒を直接読むことは難しいので普通に年月日が出力したい。

のでこうする。

log4j2.xml
<JsonLayout>
	<!-- 略 -->
	<KeyValuePair key="timestamp" value="$${date:yyyy-MM-dd'T'HH:mm:ss,SSSXXX}"/>
</JsonLayout>

結果

log.json
{
	"timestamp": "2019-07-18T07:40:42,895+09:00"
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?