4

I'm a relatively new PHP programmer, my background is in Java. My question involves attempting to log function call entry and exits using Log4PHP. I am following a loose MVC pattern where I have PHP pages that render the view, PHP scripts to act as controller and PHP classes representing the model.

This is what is happening: I have a form that submits to the PHP controller, which then instantiates a PHP class. The newly created object does an insert into MySQL, returning the new auto-increment ID. Control then passes back to the controller, which forwards to a different PHP view, using header->location. Finally, the new PHP view does a select on the newly created ID.

The problem is that during this execution process, ONLY the lookup is being logged by Log4PHP; the INSERT is not. Here are some snippets:

<appender name="myConsoleAppender" class="LoggerAppenderConsole" />   
<appender name="myLoggerAppenderDailyFile" class="LoggerAppenderDailyFile">
 <layout class="LoggerLayoutPattern">
       <param name="conversionPattern" value="%d{Y-m-d H:i:s} [%p] %c: %m (at %F line %L)%n" />
   </layout>
   <param name="file" value="file-%s.log" />
   <param name="datePattern" value="Y-m-d" />
</appender>
<logger name="merchant">
<appender_ref ref="myLoggerAppenderDailyFile" />
</logger>   
<root>
<level value="DEBUG" />
<appender_ref ref="myConsoleAppender" />
</root>
</configuration>

The constructor:

public function __construct() {
.
.
Logger::configure('config.xml');
$this->log = Logger::getLogger(__CLASS__);
}

The two methods:

public function insertMerchant() {
$this->log->debug("Inserting new Merchant");
.
.
$this->log->debug("Merchant Inserted; ID = $merchantId");
}

public function findMerchantByUserId($userId) {
$this->log->debug("Finding Merchant with userId = $userId");
.
.
$this->log->debug("Merchant found with userId = $userId");
}

As I mentioned, ONLY the LAST call to findMerchantByUserId($userid) is being logged to file. The insert is never logged,

Thanks in advance for any help.

ForIEq0
  • 41
  • 2

0 Answers0