ifeilong / feilong-spring

:gem:focus on spring
Apache License 2.0
4 stars 12 forks source link

MonitorInterceptor 日志 ,支持过滤不显示某些参数 #155

Closed venusdrogon closed 5 years ago

venusdrogon commented 6 years ago

image

venusdrogon commented 5 years ago

20:51:33 DEBUG (MonitorInterceptor.java:85) doPreHandle() - [Request] base info:    {
        "requestFullURL": "http://localhost:8091/account/findFavoritesByMemberIdAndItemIds.json?itemId=10241&_=1561899090516",
        "requestMethod": "GET",
        "parameters":         {
            "_": ["1561899090516"],
            "itemId": ["10241"]
        }
    } ,start StopWatch
venusdrogon commented 5 years ago

      <!-- MonitorInterceptor 主要在log里面输出耗时时间,以及控制台输出请求信息 -->
        <mvc:interceptor>
            <!-- 默认所有 -->
            <!-- json请求不排除 -->
            <mvc:mapping path="/**" />

            <bean class="com.feilong.spring.web.servlet.interceptor.monitor.MonitorInterceptor">

                <!-- 是否需要执行 preHandle方法 since feilong spring 1.12.9 -->
                <property name="isNeedDoPreHandle" value="true" />
                <!-- 是否需要执行 postHandle方法. since feilong spring 1.12.9 -->
                <property name="isNeedDoPostHandle" value="true" />
                <!-- 是否需要执行 AfterCompletion 方法. since feilong spring 1.12.9 -->
                <property name="isNeedDoAfterCompletion" value="true" />
                <!-- 是否需要执行 AfterConcurrentHandlingStarted 方法. since feilong spring 1.12.9 -->
                <property name="isNeedDoAfterConcurrentHandlingStarted" value="true" />

                <property name="monitorMessageEntity">
                    <bean class="com.feilong.spring.web.servlet.interceptor.monitor.MonitorMessageEntity">
                        <!-- 性能阀值,单位毫秒 -->
                        <property name="performanceThreshold" value="2000" />

                        <property name="isShowRequestAttribute" value="false" />
                        <property name="isShowPostHandleLog" value="false" />
                        <property name="isShowAfterCompletionLog" value="false" />
                        <property name="isShowAfterConcurrentHandlingStartedLog" value="false" />

                        <property name="requestLogSwitch">
                            <util:constant static-field="com.feilong.servlet.http.entity.RequestLogSwitch.NORMAL" />
                        </property>

                        <!-- 敏感参数, since feilong spring 1.12.7 -->
                        <property name="sensitiveRequestParamNameList">
                            <util:list>
                                <value>username</value>
                            </util:list>
                        </property>

                        <!-- since feilong spring 4.0.6 -->
                        <property name="ignoreRequestParamNames">
                            <util:list>
                                <value>_</value>
                            </util:list>
                        </property>

                        <!-- 允许被json log输出的 request&&model 对象类型, 默认只有基本类型以及数组才会被输出. -->
                        <property name="allowFormatClassTypes">
                            <array>
                                <!-- <value>com.feilong.web.command.ViewCommand</value> -->
                            </array>
                        </property>
                    </bean>
                </property>
            </bean>

        </mvc:interceptor>
venusdrogon commented 5 years ago

新增 ignoreRequestParamNames

效果

22:36:34 DEBUG (MonitorInterceptor.java:85) doPreHandle() - [Request] base info:    {
        "requestFullURL": "http://localhost:8091/product/reviews/show.json?storeId=2&style=PIM-7129257735AD1F3B6E5BE8&pageNo=1&_=1561905392582",
        "requestMethod": "GET",
        "parameters":         {
            "pageNo": ["1"],
            "storeId": ["2"],
            "style": ["PIM-7129257735AD1F3B6E5BE8"]
        }
    } ,start StopWatch