Configure log4j2 programmatically using ConfigurationFactory

泪湿孤枕 提交于 2019-11-29 02:16:54

In log4j 2.x you have to specify the date format in this way

public static final String LOG_FILE_NAME_PATTERN = LOG_FILE_NAME + "-%d{dd-MM-yyy}";
  • % marks the beginning of a format
  • d means that it is a date format (you can also use date)
  • within the curly braces {} you define the formatter's options. In this case the date format. You can use everything that a SimpleDateFormat would accept.

In addition you can also use:

  • %d{ABSOLUTE} -> HH:mm:ss,SSS
  • %d{COMPACT} -> yyyyMMddHHmmssSSS
  • %d{DATE} -> dd MMM yyyy HH:mm:ss,SSS
  • %d{ISO8601_BASIC} -> yyyyMMdd HHmmss,SSS
  • %d{ISO8601} -> yyyy-MM-dd HH:mm:ss,SSS

Note: This information is based on log4j 2.0-beta9 (the current release). Since it is a beta version it might change slightly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!