Understanding logback.xml file

I am using the following file in my java maven project :
<?xml version="1.0" encoding="UTF-8"?>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
        </encoder>    </appender>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->

            <!-- keep 30 days' worth of history capped at 3GB total size -->


            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n

    <logger name="chatAdapter" level="debug" additivity="false">
        <appender-ref ref="STDOUT" />
    <logger name="SMRunner" level="debug" additivity="false">
        <appender-ref ref="STDOUT" />
    <logger name="stateMachine" level="debug" additivity="false">
        <appender-ref ref="STDOUT" />

    <root level="error">
        <appender-ref ref="STDOUT"/>

Open in new window

This file resides in my top directory and inside it i have different modules like chatAdapter, stateMachine etc.

I have two questions :
1) Whats the meaning of defining root tag here ? Is it doing anything
2) As all of chatAdapter, stateMachine etc.. have the same logging conditions... Can i somehow avoid writing all of them and specify a common one for all the modules and yet have only one logback.xml file in the  project ?

Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amitkumar PSr. ConsultantCommented:
Root tag defines a Root logger. There must be at least on logger in every logging framework, otherwise its useless. Logback mandates to have root logger. Additional loggers, using logger tag, are optional. It can be used to define logger with different log levels (and different appenders, if needed).

In your case you have defined root logger with error level, and logger are with debug level. Appender (STDOUT) is common for all. So you can keep root logger and only one logger in logback.

In future based on requirement, you can add more loggers with different level or different appender for different modules.

You can refer the manual at http://logback.qos.ch/manual/configuration.html

Hope it helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.