How to use log() in Model/Entity/Bookmark.php CakePHP 3

Written by James McDonald

March 2, 2016

In CakePHP 2.x I could insert $this->log() just about anywhere and it worked.

Was just trying to do the same in CakePHP 3 from inside the file src/Model/Entity/Bookmark.php I received an error message

“Call to undefined method App\Model\Entity\Bookmark::log()”

To fix this you need to add 2 use statements one at the top of the file and one inside the class declaration


namespace App\Model\Entity;

use Cake\ORM\Entity;
use Cake\Collection\Collection;

// add use statement for LogTrait
use Cake\Log\LogTrait;

class Bookmark extends Entity {

    // add the use LogTrait
    use LogTrait;

    protected function _getTagString() {
        // now you can use $this->log()
        $this->log(["old" => "macdonald"]);



Submit a Comment

Your email address will not be published.

You May Also Like…

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...