SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Overriding log level defined in logback.xml on startup #199

Closed donatomarro closed 7 years ago

donatomarro commented 7 years ago

Hi,

it seems that the log level defined in the logback.xml is getting overridden by the log level defined in the restheart.yml on startup when starting Restheart using:

java -Dlogback.configurationFile=etc/logback.xml -server -jar restheart.jar etc/restheart.yml

I'm using the following setup: Restheart 3.0.1 / MongoDB 3.4.2 / Windows 10 64bit / Java 1.8.0_112

Log configuration within restheart.yml:

enable-log-file: false
#log-file-path: /tmp/restheart.log
enable-log-console: true
log-level: INFO
requests-log-level: 1

Content of logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>true</withJansi>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %highlight(%-5level) %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

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

    <logger name="org.restheart" level="ERROR"/>
</configuration>

The logback.xml is definitely read by restheart on startup because the periodical scan is correctly activated. But logging is performed with the log level defined in the restheart.yml. Forcing a reload of the logback.xml by touching or editing it will then result into logging with the log level defined in the logback.xml.

My expectation is that the log level from the logback.xml should be used right away from the startup of Restheart.

ujibang commented 7 years ago

hi @donatomarro

the restheart.jar file already contains the file logback.xml, this is what is taken into account by logback (see more at logback configuration)

just replace this file with yours in the jar and it will work...

donatomarro commented 7 years ago

Ciao Andrea,

I would like to provide an external configuration file so that I can change the logging configuration while having restheart running.

The above link to the logback configuration page also mentions this option:

Specifying the location of the default configuration file as a system property

You may specify the location of the default configuration file with a system property named "logback.configurationFile".

You can see that this property is taken into account because the logback.xml that is packed within the jar doesn't have periodical scanning activated but mine has. And logback performs a rescan of my logback.xml because changes made to it are reflected by the logging output.

mkjsix commented 7 years ago

@donatomarro Do you feel you could open a pull request with the necessary modifications? At present we're overwhelmed with work and not sure when we'll be able to schedule this

donatomarro commented 7 years ago

@mkjsix I might let a colleague of mine have a look at it.