lithium\analysis\Logger::write PHP Method

write() public static method

Writes a message to one or more log adapters, where the adapters that are written to are the ones that respond to the given priority level.
public static write ( string $priority, string $message, array $options = [] ) : boolean
$priority string The priority of the log message to be written.
$message string The message to be written.
$options array An array of adapter-specific options that may be passed when writing log messages. Some options are also handled by `Logger` itself: - `'name'` _string_: This option can be specified if you wish to write to a specific adapter configuration, instead of writing to the adapter(s) that respond to the given priority.
return boolean Returns `true` if all log writes succeeded, or `false` if _any or all_ writes failed.
    public static function write($priority, $message, array $options = array())
    {
        $defaults = array('name' => null);
        $options += $defaults;
        $result = true;
        if (isset(self::$_configurations[$options['name']])) {
            $name = $options['name'];
            $methods = array($name => static::adapter($name)->write($priority, $message, $options));
        } elseif (!isset(static::$_priorities[$priority])) {
            $message = "Attempted to write log message with invalid priority `{$priority}`.";
            throw new UnexpectedValueException($message);
        } else {
            $methods = static::_configsByPriority($priority, $message, $options);
        }
        foreach ($methods as $name => $method) {
            $params = compact('priority', 'message', 'options');
            $config = static::_config($name);
            if (!static::_filter(__FUNCTION__, $params, $method, $config['filters'])) {
                $result = false;
            }
        }
        return $methods ? $result : false;
    }

Usage Example

示例#1
0
 /**
  * Tests the correct writing to the cache adapter. In this test we use the
  * "Memory" cache adapter so that we can easily verify the written message.
  */
 public function testWrite()
 {
     $message = "CacheLog test message...";
     $result = Logger::write('info', $message, array('name' => 'cachelog'));
     $this->assertNotEmpty($result);
     $result = CacheStorage::read('cachelog', 'cachelog_testkey');
     $this->assertEqual($message, $result);
 }
All Usage Examples Of lithium\analysis\Logger::write