我是log4j2的新手,并尝试将log4j2.xml配置转换为log4j2.properties中的akey值对,现在几天
<Jdbc name="databaseAppender" tableName="APPLOGS">
<DataSource jndiName="com.a.b.c"/>
<Column name="ENTRY_DATE" isEventTimestamp="true" />
<Column name="LOGLEVEL" pattern="%level" />
<Column name="LOGGER" pattern="%logger" />
<Column name="MESSAGE" pattern="%message" />
<Column name="EXCEPTION" pattern="%throwable " />
</Jdbc>
我使用spring-boot-starter-log4j2
作为我的log4j2而spring-boot-starter-parent
版本是2.0.0.RELEASE
。还请注意我已经尝试了this问题的答案并获得了以下异常< / p>
Caused by: org.apache.logging.log4j.core.config.ConfigurationException: No name attribute provided for Appender dbAppender
非常感谢任何人都可以就此事提出解决方案。谢谢提前
答案 0 :(得分:0)
这里是一个示例(log4j2.properties):
foo="bar, harbor"
url=http://city.com/start_city=Boston, MAUS&end_city=New York, NY US
is_test=false
application.properties:
name=PropertiesConfig
status = error
dest = out
appender.db.type = JDBC
appender.db.name = DB
appender.db.connectionSource.type= DriverManager
appender.db.connectionSource.connectionString = <jdbc_db_url>
appender.db.connectionSource.username = <user>
appender.db.connectionSource.password = <password>
appender.db.connectionSource.driverClassName = org.postgresql.Driver
appender.db.tableName = logs
appender.db.columnConfigs[0].type = Column
appender.db.columnConfigs[0].name = userid
appender.db.columnConfigs[0].pattern =%X{username}
appender.db.columnConfigs[0].isUnicode =false
appender.db.columnConfigs[1].type = Column
appender.db.columnConfigs[1].name = message
appender.db.columnConfigs[1].pattern =%msg
appender.db.columnConfigs[1].isUnicode =false
rootLogger.level = debug
rootLogger.appenderRefs = database
rootLogger.appenderRef.database.ref = DB
在此处查看更多选项:https://logging.apache.org/log4j/2.0/manual/appenders.html#JDBCAppender