Access Log

Config dubbo access log

If you want to log the access information for each provide service,you can turn on the accesslog switch,which like the access log of Apache.

Logging by logging framework

<dubbo:protocol accesslog="true" .../>

The above configuration will turn on accesslog switch for all provide services,and logging the access log with logging framework(log4j/logback/slf4j…).You can config the logging framework of logger and appender for logging the access log.The simplest way is config logger name with dubbo.accesslog. The Example:

<appender name="accesslogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${loggingRoot}/accesslog/logging.log</file>
        <encoding>${loggingCharset}</encoding>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${loggingRoot}/accesslog/%d{yyyyMMdd}/logging.log.%d{yyyyMMdd}%i.gz
            </FileNamePattern>
            <MaxHistory>15</MaxHistory>
            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <MaxFileSize>1024MB</MaxFileSize>
            </TimeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern><![CDATA[%level|%d{yyyy-MM-dd HH:mm:ss}|%m%n}]]></pattern>
        </layout>
</appender>
<logger name="dubbo.accesslog" level="INFO" additivity="false">
        <appender-ref ref="accesslogAppender"/>
</logger>

The above is the demonstration of logback framework.Other logging framework is same too. It will logging the access log of all provide services into single file(accesslog/logging.log). And you can also config the access log of each provide service to logging separately,Only change name attribute of the logger tag,set the name attribute to dubbo.accesslog.serviceInterfaceClassFullName.The Example:

<logger name="dubbo.accesslog.com.dubbo.FooServiceInterface" level="INFO" additivity="false">
        <appender-ref ref="fooServiceAccesslogAppender"/>
</logger>

If you only want logging the access log of specified provide service,but not all services, it’s supported too.The Example:

<dubbo:service accesslog="true" .../>

Logging by specified file path

You can specify the file path with the accesslog attribute.The Example:

<dubbo:protocol accesslog="/home/admin/logs/service/accesslog.log" .../>

OR

<dubbo:service accesslog="/home/admin/logs/service/accesslog.log" .../>

Last modified November 25, 2020: fix sample code issue for SPI.md (#659) (0576d68)