File: composite.phpt

package info (click to toggle)
php-log 1.13.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: php: 1,917; xml: 593; makefile: 11; sql: 8
file content (97 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--TEST--
Log: Composite Handler
--INI--
date.timezone=UTC
--FILE--
<?php

require_once 'Log.php';

function printOpenStates($children) {
    foreach ($children as $child) {
        $state = ($child->_opened) ? 'OPEN' : 'CLOSED';
        echo "$child->_ident : $state\n";
    }
}

function printIdents($children) {
    foreach ($children as $child) {
        echo "$child->_ident\n";
    }
}

function testPriority($composite, $priority) {
    $log = new Log;
    $name = $log->priorityToString($priority);
    $success = $composite->log($name, $priority);
    echo "$name : " . (($success) ? 'GOOD' : 'BAD') . "\n";
}

/* Create three handlers with different priority masks. */
$conf = array('lineFormat' => '%2$s [%3$s] %4$s');
$children = array(
    Log::factory('console', '', 'CONSOLE1', $conf),
    Log::factory('console', '', 'CONSOLE2', $conf),
    Log::factory('console', '', 'CONSOLE3', $conf)
);

$children[0]->setMask(Log::MASK(PEAR_LOG_DEBUG));
$children[1]->setMask(Log::MASK(PEAR_LOG_INFO));
$children[2]->setMask(Log::MASK(PEAR_LOG_ERR));

$composite = Log::singleton('composite');
$composite->addChild($children[0]);
$composite->addChild($children[1]);
$composite->addChild($children[2]);

/* Verify that all of the children are initially closed. */
printOpenStates($children);

/* Verify that the composite handler's open() opens all of the children. */
$composite->open();
printOpenStates($children);

/* Verify that the composite handler's close() closes all of the children. */
$composite->close();
printOpenStates($children);

/* Verify the log results at different priorities. */
testPriority($composite, PEAR_LOG_DEBUG);
printOpenStates($children);
testPriority($composite, PEAR_LOG_INFO);
printOpenStates($children);
testPriority($composite, PEAR_LOG_ERR);
printOpenStates($children);

/* Verify that changing the ident affects all children. */
$composite->setIdent('IDENT');
printIdents($children);

--EXPECT--
CONSOLE1 : CLOSED
CONSOLE2 : CLOSED
CONSOLE3 : CLOSED
CONSOLE1 : OPEN
CONSOLE2 : OPEN
CONSOLE3 : OPEN
CONSOLE1 : CLOSED
CONSOLE2 : CLOSED
CONSOLE3 : CLOSED
CONSOLE1 [debug] debug
debug : GOOD
CONSOLE1 : OPEN
CONSOLE2 : CLOSED
CONSOLE3 : CLOSED
CONSOLE2 [info] info
info : GOOD
CONSOLE1 : OPEN
CONSOLE2 : OPEN
CONSOLE3 : CLOSED
CONSOLE3 [error] error
error : GOOD
CONSOLE1 : OPEN
CONSOLE2 : OPEN
CONSOLE3 : OPEN
IDENT
IDENT
IDENT