~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Log/Formatter/Simple.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Log
 
17
 * @subpackage Formatter
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 * @version    $Id: Simple.php 10725 2008-08-06 16:01:05Z cadorn $
 
21
 */
 
22
 
 
23
/** Zend_Log_Formatter_Interface */
 
24
require_once 'Zend/Log/Formatter/Interface.php';
 
25
 
 
26
/** Zend_Log_Exception */
 
27
require_once 'Zend/Log/Exception.php';
 
28
 
 
29
/**
 
30
 * @category   Zend
 
31
 * @package    Zend_Log
 
32
 * @subpackage Formatter
 
33
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
34
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
35
 * @version    $Id: Simple.php 10725 2008-08-06 16:01:05Z cadorn $
 
36
 */
 
37
class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface
 
38
{
 
39
    /**
 
40
     * @var string
 
41
     */
 
42
    protected $_format;
 
43
 
 
44
    const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message%';
 
45
 
 
46
    /**
 
47
     * Class constructor
 
48
     *
 
49
     * @param  null|string  $format  Format specifier for log messages
 
50
     * @throws Zend_Log_Exception
 
51
     */
 
52
    public function __construct($format = null)
 
53
    {
 
54
        if ($format === null) {
 
55
            $format = self::DEFAULT_FORMAT . PHP_EOL;
 
56
        }
 
57
 
 
58
        if (! is_string($format)) {
 
59
            throw new Zend_Log_Exception('Format must be a string');
 
60
        }
 
61
 
 
62
        $this->_format = $format;
 
63
    }
 
64
 
 
65
    /**
 
66
     * Formats data into a single line to be written by the writer.
 
67
     *
 
68
     * @param  array    $event    event data
 
69
     * @return string             formatted line to write to the log
 
70
     */
 
71
    public function format($event)
 
72
    {
 
73
        $output = $this->_format;
 
74
        foreach ($event as $name => $value) {
 
75
 
 
76
            if ((is_object($value) && !method_exists($value,'__toString'))
 
77
                || is_array($value)) {
 
78
 
 
79
                $value = gettype($value);  
 
80
            }
 
81
 
 
82
            $output = str_replace("%$name%", $value, $output);
 
83
        }
 
84
        return $output;
 
85
    }
 
86
 
 
87
}