Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Requires: phpFox version 4.5.3 or later.

...

Log System

Supporting log methods

phpFox supports 8 log methods which represent 8 levels as below.

  • emergency: System is unusable.
  • alert: Action must be taken immediately.
  • critical: Critical conditions.
  • error: Runtime errors that do not require immediate action but should typically be logged and monitored.
  • warning: Exceptional occurrences that are not errors.
  • notice: Normal but significant events.
  • info: Interesting events, Example: User logs in, SQL logs.
  • debug: Detailed debug information.

Log file location

Log file will be put to file *.log under directory PF.Base/file/log.

How to log?

In order to log, we must get log manager first using getLog function of class Phpfox. After that, use suitable method to log your message. View below examples for more details.

Examples

Simple message, append log to PF.Base/file/log/main.log;

Code Block
php
php

\Phpfox::getLog('main.log')->notice('how to do this text');

With context data, append log to PF.Base/file/log/debug.log;

Code Block
php
php

\Phpfox::getLog('debug.log')->debug('{0} does not have name', ['OvalSky']);
// write message log "Ovalsky does not have name"

Log message with level error

Code Block
php
php

$logger  =  \Phpfox::getLog('debug.log');

// write error log 
$logger->error($message);

// others LoggerInterface method
// emergency, alert, critical, error, warning, notice, info, debug

Error Handler

Since version 4.5.3, phpFox use own defined Error Handler and deprecate old Error Handler in filp/whoops package.

Error Handler will append error log to PF.Base/file/main.log file.

Errors will be log when exception fire in runtime. Fatal error will stop process and throw error code, use that error code to find out the reason of that error in PF.Base/file/log/main.log.

In order to keep the file is not be too large, a cron job will rotate file to main.log.1, main.log.2 whenever filesize exceed 5 Mb.

List of phpFox log files

  • main.log: log errors
  • mail.log: log send email errors
  • cron.log: log number of cron jobs ran and errors when cron job execute.
  • installation.log: log errors in installation and upgrade process.

Debug on screen

In order to show error on screen when developing, append below line to PF.Base/file/settings/debug.sett.php.

Code Block
php
php

define('PHPFOX_DEBUG_ON_SCREEN', true);