Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
--TEST--
2
Log: Composite Handler
3
--INI--
4
date.timezone=UTC
5
--FILE--
6
<?php
7
 
8
require_once 'Log.php';
9
 
10
function printOpenStates($children) {
11
    foreach ($children as $child) {
12
        $state = ($child->_opened) ? 'OPEN' : 'CLOSED';
13
        echo "$child->_ident : $state\n";
14
    }
15
}
16
 
17
function printIdents($children) {
18
    foreach ($children as $child) {
19
        echo "$child->_ident\n";
20
    }
21
}
22
 
23
function testPriority($composite, $priority) {
24
    $name = Log::priorityToString($priority);
25
    $success = $composite->log($name, $priority);
26
    echo "$name : " . (($success) ? 'GOOD' : 'BAD') . "\n";
27
}
28
 
29
/* Create three handlers with different priority masks. */
30
$conf = array('lineFormat' => '%2$s [%3$s] %4$s');
31
$children = array(
32
    Log::singleton('console', '', 'CONSOLE1', $conf),
33
    Log::singleton('console', '', 'CONSOLE2', $conf),
34
    Log::singleton('console', '', 'CONSOLE3', $conf)
35
);
36
 
37
$children[0]->setMask(Log::MASK(PEAR_LOG_DEBUG));
38
$children[1]->setMask(Log::MASK(PEAR_LOG_INFO));
39
$children[2]->setMask(Log::MASK(PEAR_LOG_ERR));
40
 
41
$composite = Log::singleton('composite');
42
$composite->addChild($children[0]);
43
$composite->addChild($children[1]);
44
$composite->addChild($children[2]);
45
 
46
/* Verify that all of the children are initially closed. */
47
printOpenStates($children);
48
 
49
/* Verify that the composite handler's open() opens all of the children. */
50
$composite->open();
51
printOpenStates($children);
52
 
53
/* Verify that the composite handler's close() closes all of the children. */
54
$composite->close();
55
printOpenStates($children);
56
 
57
/* Verify the log results at different priorities. */
58
testPriority($composite, PEAR_LOG_DEBUG);
59
printOpenStates($children);
60
testPriority($composite, PEAR_LOG_INFO);
61
printOpenStates($children);
62
testPriority($composite, PEAR_LOG_ERR);
63
printOpenStates($children);
64
 
65
/* Verify that changing the ident affects all children. */
66
$composite->setIdent('IDENT');
67
printIdents($children);
68
 
69
--EXPECT--
70
CONSOLE1 : CLOSED
71
CONSOLE2 : CLOSED
72
CONSOLE3 : CLOSED
73
CONSOLE1 : OPEN
74
CONSOLE2 : OPEN
75
CONSOLE3 : OPEN
76
CONSOLE1 : CLOSED
77
CONSOLE2 : CLOSED
78
CONSOLE3 : CLOSED
79
CONSOLE1 [debug] debug
80
debug : GOOD
81
CONSOLE1 : OPEN
82
CONSOLE2 : CLOSED
83
CONSOLE3 : CLOSED
84
CONSOLE2 [info] info
85
info : GOOD
86
CONSOLE1 : OPEN
87
CONSOLE2 : OPEN
88
CONSOLE3 : CLOSED
89
CONSOLE3 [error] error
90
error : GOOD
91
CONSOLE1 : OPEN
92
CONSOLE2 : OPEN
93
CONSOLE3 : OPEN
94
IDENT
95
IDENT
96
IDENT