posts - 37,comments - 7,trackbacks - 0
          public aspect TraceAspect{
             private Logger _logger = Logger.getLogger("trace");
             pointcut traceMethods(): execution(* *.*(..))&&!within(TraceAsptect);
             before() : traceMethods(){
                Signature sig = thisJoinPointStaticPart.getSignature();
                _logger.logp(Level.INFO, sig.getDeclaringType().getName(), sig.getName(), "Entering");
            }
          }

          What’s wrong with conventional logging ?

          When a new module is added to the system, all of its methods that need logging must be instrumented. Such instrumentation is invasive, causing the tangling of the core concerns with the logging concern. Further, if you ever happen to change the logging toolkit to a different API, you need to revisit every logging statement and modify it.

          Consistency is the single most important requirement of logging. It means that if the logging specification requires that certain kinds of operations be logged, then the implementation must log every invocation of those operations. When things go wrong in a system, doubting the logging consistency is probably the last thing you want to do. Missed logging calls can make output hard to understand and sometimes useless. Achieving consistency using conventional logging is a lofty goal, and while systems can attain it initially, it requires continuing vigilance to keep it so. For example, if you add new classes to the system or new methods in existing classes, you must ensure that they implement logging that matches the current logging strategy.

          The beauty of AspectJ-based logging

          The limitations are not a result of the logging APIs or their implementations; rather, they stem from the fundamental limitations of objectoriented programming, which require embedding the logging invocations in each module. AOP and AspectJ overcome those limitations. AspectJ easily implements the invocation of logging statements from all the log points. The beauty is that you do not need to actually instrument any log points; writing an aspect does it automatically. Further, since there is a central place to control logging operations, you achieve consistency easily.

          The most fundamental difference between conventional logging and AspectJbased logging is modularization of the logging concern. Instead of writing modules that implement core concepts in addition to invoking logging operations, with AspectJ you write a few aspects that advise the execution of the operations in the core modules to perform the logging. That way, the core modules do not carry any logging-related code. By modularizing, you separate the logging concern
          from the core concerns.

          With AspectJ-based logging, the logger aspect separates the core modules and the logger object. Instead of the core modules’ embedding the log() method invocations in their source code, the logger aspect weaves the logging invocations into the core modules when they are needed. AspectJ-based logging reverses the dependency between the core modules and the logger; it is the aspect that encodes how the operations in the core modules are logged instead
          of each core module deciding for itself.
          posted on 2005-08-29 10:52 Dave 閱讀(815) 評(píng)論(2)  編輯  收藏

          FeedBack:
          # re: 一個(gè)使用AspectJ進(jìn)行l(wèi)ogging的例子
          2007-07-09 17:07 | 江陵二少爺
          pointcut traceMethods(): execution(* *.*(..))&&!within(TraceAsptect);
          --------------------------------------------\
          當(dāng)log方法類(lèi)型匹配寫(xiě)成這樣時(shí),系統(tǒng)的IO性能都會(huì)成大問(wèn)題。更何況,記錄的這些日志信息似乎沒(méi)有任何意義。  回復(fù)  更多評(píng)論
            
          # re: 一個(gè)使用AspectJ進(jìn)行l(wèi)ogging的例子
          2007-11-12 10:29 | licco
          你可以進(jìn)行局部匹配
            回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 宣城市| 文昌市| 钟山县| 和政县| 昌都县| 江北区| 新宾| 奈曼旗| 清流县| 肃北| 大宁县| 庆安县| 扶沟县| 江安县| 钦州市| 金堂县| 万载县| 明溪县| 海淀区| 孟连| 黄陵县| 金乡县| 尉氏县| 启东市| 关岭| 紫金县| 马鞍山市| 滦南县| 武鸣县| 大安市| 遂溪县| 尼勒克县| 黔西县| 财经| 襄樊市| 琼结县| 呈贡县| 新宾| 秀山| 交城县| 教育|