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. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…