Simon
Simon

Reputation: 4794

debug.log in CakePHP without stacktrace

I log values of variables into debug.log using:

$var = 'Hello World';
debugger::log($var);

in my /app/tmp/logs/debug.log there is the whole stacktrace for that log:

2014-03-24 20:47:42 Debug: 
UserController::create() - APP\Controller\UserController.php, line 21
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 490
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 185
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 160
[main] - APP\webroot\index.php, line 108
'Hello World'

I don´t need the stacktrace, only the value of my variable.

Upvotes: 0

Views: 1148

Answers (1)

Linas Butenas
Linas Butenas

Reputation: 171

One of the solutions is to use CakeLog::write function

CakeLog::write(LOG_DEBUG, "your message");

You will get the output to debug.log file:

2014-07-21 16:08:25 Debug:
your message

It is impossible to remove stack trace from debugger::log($var). Why? Here is its CakePHP code from Debugger.php:

public static function log($var, $level = LOG_DEBUG, $depth = 3) {
    $source = self::trace(array('start' => 1)) . "\n";
    CakeLog::write($level, "\n" . $source . self::exportVar($var, $depth));
}

Or edit the CakePHP source :)

Upvotes: 1

Related Questions