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