XML schema or DTD for logback.xml?
Solution 1
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.
Solution 2
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.
Solution 3
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>
To get rid of the exclamation point icon after you fix it, you might need to trigger the validation again by right-clicking the file and choosing Validate
.
Solution 4
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.
Solution 5
<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
Vladislav Rastrusny
General trends: Backend developer (PHP or Java based). Architect (S.O.L.I.D. lover, Scrum-follower, DDD-fan). Microservice-trended OSes: Linux server administration (proficient). Installed from scratch and tuned LAMP-stack web servers based on CentOS for my customers. Windows desktop administration (proficient). Use Windows workstation every day. Languages: PHP (expert). From scratch development of complex websites, various custom systems and one billing&accounting system. Delphi (expert). Commercial products written. Javascript (intermediate). Not a front-end genius, but developed some custom ReactJS components for websites. Java (intermediate). Two successful projects in past: DistribuCalc and ShieldSuite CSS (beginner). Not really doing anything serious with CSS, but looking forward to try and learn things, while excercising something like BEM or OOCSS. C# (.NET, beginner). Just enjoying the power of this language. Closely watching Mono. Bash (beginner). Wrote simple automation scripts for Linux servers. Frameworks: [PHP] Laravel framework (expert). From scratch development of complex websites. [PHP] CakePHP (intermediate). Maintained a project, that was using it. [PHP] Symfony framework (beginner). Just enjoy this wonderful piece of art and follow its news. [PHP] Yii2 framework (beginner). Used it in one project. [CSS] Twitter Bootstrap (intermediate). Used in a new project. Libraries: [JS] ReactJS (intermediate). Developed custom components for one of the websites using ReactJS. [JS] jQuery (intermediate). Used it in almost all PHP projects. [Java] JOOQ. Used it in my commercial Distribucalc project. Database servers: MySQL (expert). Used in 90% of my projects from forums to billing systems. PostgreSQL (intermediate). Used it in one project as a powerful MySQL alternative. MS SQL Server (beginner). Used it as a backend storage for a retail accounting system. Tools: Git (expert). Using git branching model every day (release-, feature-, task-branching) Ansible (intermediate). Used it to build custom Vagrant environment for dev purposes. RabbitMQ (intermediate). Used as a communication method for delayed tasks using SOA. Redis (intermediate). My caching system fo the choice.
Updated on November 03, 2020Comments
-
Vladislav Rastrusny over 3 years
I've seen several discussions on the net about how great it would be to have an XML schema or DTD for logback.xml file to have at least the very basic validation and auto-completion in IDEs like IDEA or Eclipse, but I never saw any solution.
Did you?
-
Rohit Gupta almost 9 yearsWhilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
-
Vladislav Rastrusny almost 9 yearsHow complete support is there in that repo?
-
Olivier Cailloux over 7 yearsIt has now been merged. According to Github Network Graph, enricopulatzo’s schema seems to be the richest source.
-
Ken Alton about 7 yearsIn the same way that English language is extremely flexible therefore it has no grammatical rules???? What a cop-out of an excuse!
-
Jonathan E. Landrum about 7 yearsThis solution works. Just put
logback.xsd
in the same directory aslogback.xml
and add it to your project manually. In IntelliJ, for example, you'd go toSettings > Languages & Frameworks > Schemas and DTDs
and click the green "+" to add an external resource. Set "URI" tohttp://ch.qos.logback/xml/ns/logback
and "Location" to the location oflogback.xsd
. -
Osguima3 over 6 yearsI just created an url shortener for this project's logback.xsd file, and it's working as expected. You can use
xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback https://git.io/logback.xsd"
-
Shamal Karunarathne about 6 yearsAs the comment by @lucas say, use
<!DOCTYPE configuration>
. It works for meVersion: Oxygen.2 Release (4.7.2) Build id: 20171218-0600
-
gavard.e over 4 yearsFor those coming years after like me, the previous xsd location is not valid anymore. You can refer to git.io/logback.xsd as mentioned in a previous response
-
Noumenon over 4 yearsTo get rid of the exclamation point icon after you fix it, as @Manuel said, trigger the validation again by right-clicking the file and choosing "Validate".
-
Adrian Ber over 4 years@Noumenon I will add your comment to my answer. Thanks!
-
maxxyme over 3 yearseven using this, I still get validation errors on unrecognized XML elements... like
<variable
(under<configuration
)<Name
or<immediateFlush>
under an<appender
! -
raisercostin over 3 yearsI doubt that a perfect xsd will exist since logback config supports plugins and each of them is free to have their own tags.
-
maxxyme over 3 yearseven when the plugins are the ones from Logback itself? or I speak about appenders, I don't know what plugins for Logback are about. but not having a "perfect xsd" defeats the original concept of XML, i.e. having a Markup Language, which by the way is eXtensible (e.g. through additional definitions/schemas - the Spring Framework handles this perfectly well when you configure it in XML).
-
raisercostin over 3 yearsWhile you are right on xml, it is known that it has practical limits. With infinite time and effort you can make xml schema work but in the real world is not the case. I cannot say more than the official documentation: "As will be demonstrated over and over, the syntax of logback configuration files is extremely flexible. As such, it is not possible to specify the allowed syntax with a DTD file or an XML schema." - logback.qos.ch/manual/configuration.html#syntax
-
snydergd about 3 yearsDoes anyone know why this works? Just curious and not sure how to find the answer without reading a book or something similar.
-
rustyx about 2 yearsThe solution from this answer does NOT work anymore.
-
toolforger almost 2 yearsIt does not work in IntelliJ as of 2022.