4.6.1 Using the log function
Es gibt zur Zeit keine Übersetzung für diesen Abschnitt. Bitte hilf mit und übersetze ihn. Mehr Informationen zu Übersetzungen
The log() function takes two parameters. The first is the message you'd like written to the log file. By default, this error message is written to the error log found in app/tmp/logs/error.log.
//Executing this inside a CakePHP class:
$this->log("Something didn't work!");
//Results in this being appended to app/tmp/logs/error.log
2007-11-02 10:22:02 Error: Something didn't work!
//Executing this inside a CakePHP class:$this->log("Something didn't work!");//Results in this being appended to app/tmp/logs/error.log2007-11-02 10:22:02 Error: Something didn't work!
The second parameter is used to define the log type you wish to write the message to. If not supplied, it defaults to LOG_ERROR, which writes to the error log previously mentioned. You can set this second parameter to LOG_DEBUG to write your messages to an alternate debug log found at app/tmp/logs/debug.log:
//Executing this inside a CakePHP class:
$this->log('A debugging message.', LOG_DEBUG);
//Results in this being appended to app/tmp/logs/debug.log (rather than error.log)
2007-11-02 10:22:02 Error: A debugging message.
//Executing this inside a CakePHP class:$this->log('A debugging message.', LOG_DEBUG);//Results in this being appended to app/tmp/logs/debug.log (rather than error.log)2007-11-02 10:22:02 Error: A debugging message.
You can also specify a different name for the log file, by setting the second parameter to the name of the file.
//Executing this inside a CakePHP class:
$this->log('A special message for activity logging', 'activity');
//Results in this being appended to app/tmp/logs/activity.log (rather than error.log)
2007-11-02 10:22:02 Activity: A special message for activity logging
//Executing this inside a CakePHP class:$this->log('A special message for activity logging', 'activity');//Results in this being appended to app/tmp/logs/activity.log (rather than error.log)2007-11-02 10:22:02 Activity: A special message for activity logging
Your app/tmp directory must be writable by the web server user in order for logging to work correctly.


























