XML schema or DTD for logback.xml?

陌路散爱 提交于 2019-11-29 20:24:49

It is not supported officially according to the documentation, but there is an independent project to provide Schema for Logback

However, due to extreme flexibility of the Logback configuration, Schema cannot support all possible configuration options.

Eugene Yokota

As of June 2011, the official documentation states

As shall become clear, the syntax of logback configuration files is extremely flexible. As such, it is not possible specify the allowed syntax with a DTD file or an XML Schema.

There was a brief thread on the topic, but didn't seem to go anywhere.

Just to get rid of the annoying warning in Eclipse add <!DOCTYPE xml> after <?xml version="1.0" encoding="UTF-8"?>.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>

The independent project mentioned by Sergey covered most of my requirements.

However, some elements were missing, I added them on my own fork on on https://github.com/nkatsar/logback-XSD. Hope they will get merged in the main project.

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd">

from GitHub "An XML Schema Definition for logback" https://github.com/nkatsar/logback-XSD

A slightly different answer that allows eclipse autocomplete is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.padual.com/java/logback.xsd" 
    debug="true" packagingData="true" scan="true" scanPeriod="30 seconds">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!