-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLayout.class.php
More file actions
executable file
·67 lines (63 loc) · 1.62 KB
/
Layout.class.php
File metadata and controls
executable file
·67 lines (63 loc) · 1.62 KB
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
<?php namespace util\log;
use lang\Value;
/**
* Takes care of formatting log entries
*
* @test util.log.unittest.LayoutTest
*/
abstract class Layout {
/**
* Creates a string representation of the given argument.
*
* @param var $arg
* @return string
*/
protected function stringOf($arg, $indent= '') {
if (null === $arg) {
return 'null';
} else if (false === $arg) {
return 'false';
} else if (true === $arg) {
return 'true';
} else if (is_string($arg)) {
return '' === $indent ? $arg : '"'.$arg.'"';
} else if ($arg instanceof Value) {
return $arg->toString();
} else if ([] === $arg) {
return '[]';
} else if (is_array($arg)) {
if (0 === key($arg)) {
$r= '';
foreach ($arg as $value) {
$r.= ', '.$this->stringOf($value, $indent);
}
return '['.substr($r, 2).']';
} else {
$n= $indent.' ';
$r= '[';
foreach ($arg as $key => $value) {
$r.= "\n{$n}{$key} => ".$this->stringOf($value, $n);
}
return $r."\n{$indent}]";
}
} else if ($arg instanceof \Closure) {
return $arg();
} else if (is_object($arg)) {
$n= $indent.' ';
$r= nameof($arg).'@{';
foreach ((array)$arg as $key => $value) {
$r.= "\n{$n}{$key} => ".$this->stringOf($value, $n);
}
return $r."\n{$indent}}";
} else {
return (string)$arg;
}
}
/**
* Formats a logging event according to this layout
*
* @param util.log.LoggingEvent event
* @return string
*/
public abstract function format(LoggingEvent $event);
}