| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Monolog package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Monolog\Handler;
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* Interface that all Monolog Handlers must implement
|
|
|
16 |
*
|
|
|
17 |
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
18 |
*
|
|
|
19 |
* @phpstan-import-type Record from \Monolog\Logger
|
|
|
20 |
* @phpstan-import-type Level from \Monolog\Logger
|
|
|
21 |
*/
|
|
|
22 |
interface HandlerInterface
|
|
|
23 |
{
|
|
|
24 |
/**
|
|
|
25 |
* Checks whether the given record will be handled by this handler.
|
|
|
26 |
*
|
|
|
27 |
* This is mostly done for performance reasons, to avoid calling processors for nothing.
|
|
|
28 |
*
|
|
|
29 |
* Handlers should still check the record levels within handle(), returning false in isHandling()
|
|
|
30 |
* is no guarantee that handle() will not be called, and isHandling() might not be called
|
|
|
31 |
* for a given record.
|
|
|
32 |
*
|
|
|
33 |
* @param array $record Partial log record containing only a level key
|
|
|
34 |
*
|
|
|
35 |
* @return bool
|
|
|
36 |
*
|
|
|
37 |
* @phpstan-param array{level: Level} $record
|
|
|
38 |
*/
|
|
|
39 |
public function isHandling(array $record): bool;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Handles a record.
|
|
|
43 |
*
|
|
|
44 |
* All records may be passed to this method, and the handler should discard
|
|
|
45 |
* those that it does not want to handle.
|
|
|
46 |
*
|
|
|
47 |
* The return value of this function controls the bubbling process of the handler stack.
|
|
|
48 |
* Unless the bubbling is interrupted (by returning true), the Logger class will keep on
|
|
|
49 |
* calling further handlers in the stack with a given log record.
|
|
|
50 |
*
|
|
|
51 |
* @param array $record The record to handle
|
|
|
52 |
* @return bool true means that this handler handled the record, and that bubbling is not permitted.
|
|
|
53 |
* false means the record was either not processed or that this handler allows bubbling.
|
|
|
54 |
*
|
|
|
55 |
* @phpstan-param Record $record
|
|
|
56 |
*/
|
|
|
57 |
public function handle(array $record): bool;
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Handles a set of records at once.
|
|
|
61 |
*
|
|
|
62 |
* @param array $records The records to handle (an array of record arrays)
|
|
|
63 |
*
|
|
|
64 |
* @phpstan-param Record[] $records
|
|
|
65 |
*/
|
|
|
66 |
public function handleBatch(array $records): void;
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Closes the handler.
|
|
|
70 |
*
|
|
|
71 |
* Ends a log cycle and frees all resources used by the handler.
|
|
|
72 |
*
|
|
|
73 |
* Closing a Handler means flushing all buffers and freeing any open resources/handles.
|
|
|
74 |
*
|
|
|
75 |
* Implementations have to be idempotent (i.e. it should be possible to call close several times without breakage)
|
|
|
76 |
* and ideally handlers should be able to reopen themselves on handle() after they have been closed.
|
|
|
77 |
*
|
|
|
78 |
* This is useful at the end of a request and will be called automatically when the object
|
|
|
79 |
* is destroyed if you extend Monolog\Handler\Handler.
|
|
|
80 |
*
|
|
|
81 |
* If you are thinking of calling this method yourself, most likely you should be
|
|
|
82 |
* calling ResettableInterface::reset instead. Have a look.
|
|
|
83 |
*/
|
|
|
84 |
public function close(): void;
|
|
|
85 |
}
|