1: <?php
2:
3: namespace PHPixie\Debug;
4:
5: class Logger
6: {
7: protected $builder;
8: protected $items = array();
9:
10: public function __construct($builder)
11: {
12: $this->builder = $builder;
13: }
14:
15: public function log($value, $shortDump = false, $backtraceOffset = 0)
16: {
17: $trace = $this->getTrace(1, $backtraceOffset);
18: $elements = $trace->elements();
19:
20: $this->items[] = $this->builder->loggerItem(
21: $elements[0],
22: $value,
23: $shortDump
24: );
25: }
26:
27: public function trace($limit = null, $backtraceOffset = 0)
28: {
29: $trace = $this->getTrace($limit, $backtraceOffset);
30: $elements = $trace->elements();
31:
32: $this->items[] = $this->builder->loggerItem(
33: $elements[0],
34: $trace
35: );
36: }
37:
38: protected function getTrace($limit, $backtraceOffset)
39: {
40: $tracer = $this->builder->tracer();
41: return $tracer->backtrace($limit, 2+$backtraceOffset);
42: }
43:
44: public function items()
45: {
46: return $this->items;
47: }
48:
49: public function clearItems()
50: {
51: $this->items = array();
52: }
53:
54: public function getAndClearItems()
55: {
56: $items = $this->items;
57: $this->clearItems();
58: return $items;
59: }
60:
61: public function asString($withTraceArguments = true, $shortValueDump = null)
62: {
63: $string = '';
64: foreach($this->items as $key => $item) {
65: if($key > 0) {
66: $string.="\n\n";
67: }
68:
69: $string.= '#'.$key.' '.$item->asString($withTraceArguments, $shortValueDump);
70: }
71:
72: return $string;
73: }
74:
75: public function __toString()
76: {
77: return $this->asString();
78: }
79:
80: }