zoukankan      html  css  js  c++  java
  • perf4j+spring+aop 配置 注解方式

    今天将perf4j基于spring aop方式进入了接入,接入方法还是比较简单。具体配置如下:

    logback.xml

    <!--perf4j配置-->
        <appender name="statistics" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <Encoding>UTF-8</Encoding>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!--日志文件输出的文件名 -->
                <FileNamePattern>logs/statistics.%d{yyyy-MM-dd}.log</FileNamePattern>
            </rollingPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%msg%n</pattern>
            </layout>
        </appender>
    
        <appender name="coalescingStatistics" class="org.perf4j.logback.AsyncCoalescingStatisticsAppender">
            <timeSlice>10000</timeSlice>
            <appender-ref ref="statistics"/>
        </appender>
    
        <logger name="org.perf4j.TimingLogger" level="info" additivity="false">
            <appender-ref ref="coalescingStatistics" />
        </logger>
        <!--perf4j配置结束-->

    aop.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    
        <aop:config>
            <aop:aspect id="aspect" ref="timingAspect">
                <aop:pointcut id="timingCut" expression="execution(* com.xxx..*.*(..)) and @annotation(profiled))"/>
                <aop:around pointcut-ref="timingCut" method="doPerfLogging"/>
            </aop:aspect>
        </aop:config>
        <bean id="timingAspect" class="org.perf4j.slf4j.aop.TimingAspect" />
    </beans>

    当然还有更方便的配置方式

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
        <aop:aspectj-autoproxy />
    
        <bean id="timingAspect" class="org.perf4j.slf4j.aop.TimingAspect" />
    </beans>

    OK!

    现在就可以在需要监控的方法上添加@Profiled了。

  • 相关阅读:
    别让暑假留下遗憾,让我们一起去黑龙潭耍水祈福吧
    黑龙潭亲子福利:参加亲子活动合影拿好礼
    黑龙潭,北京夏日养生旅游的首选之地
    黑龙潭,一个夏日亲子游的好地方
    黑龙潭,北京真龙的栖身之所?
    密云黑龙潭周末自驾游
    白天,你陪我黑龙潭戏水观瀑;夜晚,我陪你云蒙山数星看月
    北京黑龙潭旅游攻略
    亲爱的,让我们今生约定每年都去一次黑龙潭,好吗?
    成都飞客文化2014新春贺词:感恩有你,共创辉煌
  • 原文地址:https://www.cnblogs.com/maoxiaolv/p/5577022.html
Copyright © 2011-2022 走看看