/** * Configure and add a new logging stream to CakeLog * You can use add loggers from app/Log/Engine use app.loggername, or any * plugin/Log/Engine using plugin.loggername. * * ### Usage: * * ``` * CakeLog::config('second_file', array( * 'engine' => 'File', * 'path' => '/var/logs/my_app/' * )); * ``` * * Will configure a FileLog instance to use the specified path. * All options that are not `engine` are passed onto the logging adapter, * and handled there. Any class can be configured as a logging * adapter as long as it implements the methods in CakeLogInterface. * * ### Logging levels * * When configuring loggers, you can set which levels a logger will handle. * This allows you to disable debug messages in production for example: * * ``` * CakeLog::config('default', array( * 'engine' => 'File', * 'path' => LOGS, * 'levels' => array('error', 'critical', 'alert', 'emergency') * )); * ``` * * The above logger would only log error messages or higher. Any * other log messages would be discarded. * * ### Logging scopes * * When configuring loggers you can define the active scopes the logger * is for. If defined only the listed scopes will be handled by the * logger. If you don't define any scopes an adapter will catch * all scopes that match the handled levels. * * ``` * CakeLog::config('payments', array( * 'engine' => 'File', * 'types' => array('info', 'error', 'warning'), * 'scopes' => array('payment', 'order') * )); * ``` * * The above logger will only capture log entries made in the * `payment` and `order` scopes. All other scopes including the * undefined scope will be ignored. Its important to remember that * when using scopes you must also define the `types` of log messages * that a logger will handle. Failing to do so will result in the logger * catching all log messages even if the scope is incorrect. * * @param string $key The keyname for this logger, used to remove the * logger later. * @param array $config Array of configuration information for the logger * @return bool success of configuration. * @throws CakeLogException * @link http://book.cakephp.org/2.0/en/core-libraries/logging.html#creating-and-configuring-log-streams */ public static function config($key, $config) { if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $key)) { throw new CakeLogException(__d('cake_dev', 'Invalid key name')); } if (empty($config['engine'])) { throw new CakeLogException(__d('cake_dev', 'Missing logger class name')); } if (empty(static::$_Collection)) { static::_init(); } static::$_Collection->load($key, $config); return true; }
/** * Configures the automatic/default stream a FileLog. * * @return void */ protected static function _autoConfig() { self::$_Collection->load('default', array('engine' => 'File', 'path' => LOGS)); }