1: <?php
2:
3: namespace Psr\Log;
4:
5: /**
6: * This is a simple Logger trait that classes unable to extend AbstractLogger
7: * (because they extend another class, etc) can include.
8: *
9: * It simply delegates all log-level-specific methods to the `log` method to
10: * reduce boilerplate code that a simple Logger that does the same thing with
11: * messages regardless of the error level has to implement.
12: */
13: trait LoggerTrait
14: {
15: /**
16: * System is unusable.
17: *
18: * @param string $message
19: * @param array $context
20: */
21: public function emergency($message, array $context = array())
22: {
23: $this->log(LogLevel::EMERGENCY, $message, $context);
24: }
25:
26: /**
27: * Action must be taken immediately.
28: *
29: * Example: Entire website down, database unavailable, etc. This should
30: * trigger the SMS alerts and wake you up.
31: *
32: * @param string $message
33: * @param array $context
34: */
35: public function alert($message, array $context = array())
36: {
37: $this->log(LogLevel::ALERT, $message, $context);
38: }
39:
40: /**
41: * Critical conditions.
42: *
43: * Example: Application component unavailable, unexpected exception.
44: *
45: * @param string $message
46: * @param array $context
47: */
48: public function critical($message, array $context = array())
49: {
50: $this->log(LogLevel::CRITICAL, $message, $context);
51: }
52:
53: /**
54: * Runtime errors that do not require immediate action but should typically
55: * be logged and monitored.
56: *
57: * @param string $message
58: * @param array $context
59: */
60: public function error($message, array $context = array())
61: {
62: $this->log(LogLevel::ERROR, $message, $context);
63: }
64:
65: /**
66: * Exceptional occurrences that are not errors.
67: *
68: * Example: Use of deprecated APIs, poor use of an API, undesirable things
69: * that are not necessarily wrong.
70: *
71: * @param string $message
72: * @param array $context
73: */
74: public function warning($message, array $context = array())
75: {
76: $this->log(LogLevel::WARNING, $message, $context);
77: }
78:
79: /**
80: * Normal but significant events.
81: *
82: * @param string $message
83: * @param array $context
84: */
85: public function notice($message, array $context = array())
86: {
87: $this->log(LogLevel::NOTICE, $message, $context);
88: }
89:
90: /**
91: * Interesting events.
92: *
93: * Example: User logs in, SQL logs.
94: *
95: * @param string $message
96: * @param array $context
97: */
98: public function info($message, array $context = array())
99: {
100: $this->log(LogLevel::INFO, $message, $context);
101: }
102:
103: /**
104: * Detailed debug information.
105: *
106: * @param string $message
107: * @param array $context
108: */
109: public function debug($message, array $context = array())
110: {
111: $this->log(LogLevel::DEBUG, $message, $context);
112: }
113:
114: /**
115: * Logs with an arbitrary level.
116: *
117: * @param mixed $level
118: * @param string $message
119: * @param array $context
120: */
121: abstract public function log($level, $message, array $context = array());
122: }
123: