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