Feature #3312

Allow for easy logging by annotations

Added by Robert Lemke over 12 years ago. Updated about 11 years ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
Category:
Log
Target version:
-
Start date:
2009-05-15
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
Complexity:

Description

For debugging but also other purposes, it would be nice to be able to log a method call by just adding an annotation to it.

This logs any call of the method into the SystemLogger with severity level "DEBUG" and stores the argument values in the additionalData arg:

/**
 * A method
 * 
 * @param string $someArgument
 * @return string 
 * @log before
public function myMethod($someArgument) {
   ...
}

This is identical:

/**
 * A method
 * 
 * @param string $someArgument
 * @return string 
 * @log before (logger = SystemLogger)
public function myMethod($someArgument) {
   ...
}

Here the method invokation is logged to a logger with identifier "MyLog", with severity WARNING

/**
 * A method
 * 
 * @param string $someArgument
 * @return string 
 * @log before (logger = MyLog, severity = WARNING)
public function myMethod($someArgument) {
   ...
}

This logs the method call with a custom message:

/**
 * A method
 * 
 * @param string $someArgument
 * @return string 
 * @log before (message = "Called my method with $someArgument")
public function myMethod($someArgument) {
   ...
}

This logs the method call and the returning:

/**
 * A method
 * 
 * @param string $someArgument
 * @return string 
 * @log around
public function myMethod($someArgument) {
   ...
}

So basically you have the same types like for AOP advices:

  • @log before
  • @log after
  • @log afterReturning
  • @log afterThrowing
  • @log around

Also available in: Atom PDF