Question

I am facing a strange behavior by CakePHP 2.1:

I have a method, $this->Time->getTime(); which always logs an action, then returns true. When called from the browser, it works as expected: logs the action, then returns true.

I created a shell, TimeShell, in which I log another action only if $this->Time->getTime(); returns true. Now, the weird thing is that the second action is logged, hence the method returned true, but the action from the method (which obviously had to run since it passed it and returned true) isn't logged.

Why isn't the first action logged when the method is called from the shell? (if it helps, the shell is run via a cron job on my server)

EDIT

After further testing, I found out that if I don't log the second action (the one in the shell), then the first action (in $this->Time->getTime();) is correctly logged. But I can't figure out why does Cake only log the last action from those which should be logged.

Moreover, it seems that only the DatabaseLogger behaves this way, FileLog logs both actions. Very weird.

Was it helpful?

Solution

Looks like the answer was extremely simple: I forgot to call $this->Log->create(); before saving the logged action, hence the second action was overwriting the first one.

This being said, I recommend checking that you have the create(); method called if you encounter any problem with saving data (mostly when overwriting occurs). In many cases, this would be the solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top