Feature #3312

Allow for easy logging by annotations

Added by Robert Lemke about 6 years ago. Updated almost 5 years ago.

Status:Needs Feedback Start date:2009-05-15
Priority:Should have Due date:
Assigned To:Robert Lemke % Done:

0%

Category:Log
Target version:-
PHP Version: Complexity:
Has patch:

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

History

#1 Updated by Karsten Dambekalns about 6 years ago

In what way (if any) will arguments and/or return values be logged? The example with the custom message includes a variable, but what happens in other cases? And how will objects / arrays be formatted for logging?

#2 Updated by Bastian Waidelich about 6 years ago

Maybe method arguments and return values could be passed as $additionalData to the logger by default. Than the logger would decide how to represent objects/arrays.

#3 Updated by Christopher Hlubek about 6 years ago

I think objects could be formatted with __toString() for logging. Arrays should be displayed like [foo, bar], where each argument would be formatted as a string.

Regarding the variables: we will need special ones for the return value (around, after and afterReturning) and the thrown exception (if any).

I would like an additional log type @log time to log the time spent in this method. This could be used to do live profiling of certain methods (e.g. controller actions) in production.

#4 Updated by Robert Lemke about 6 years ago

  • Target version deleted (283)

Also available in: Atom PDF