-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbufferedEmail.php
40 lines (31 loc) · 1.43 KB
/
bufferedEmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
use Monolog\Formatter\HtmlFormatter;
use Monolog\Handler\FingersCrossedHandler;
use Monolog\Handler\NativeMailerHandler;
use Monolog\Logger;
require 'vendor/autoload.php';
$to = "[email protected]";
$subject = "Buffered Email Test";
$from = "[email protected]";
$mailHandler = new NativeMailerHandler($to, $subject, $from, Logger::NOTICE);
$mailHandler->setContentType('text/html');
$mailHandler->setFormatter(new HtmlFormatter());
$bufferSize = 3;
$fingersCrossed = new FingersCrossedHandler($mailHandler, Logger::CRITICAL, $bufferSize, true, false);
$logger = new Logger("phpdx-experiments-buffered.email");
$logger->pushHandler($fingersCrossed);
////////////////// EMAIL 1 ////////////////////////////////////
$logger->debug('test.debug will not be in emails or buffers');
for ($i = 0; $i < ($bufferSize - 1); $i++) {
$logger->notice('test.notice');
}
// This critical log activates a handling of the FingersCrossed buffer.
$logger->critical('test.critical');
////////////////// EMAIL 2 ////////////////////////////////////
$logger->warning('test.warning');
$logger->info('test.info will not be in emails or buffers');
// This emergency log activates a second handling of the FingersCrossed buff
$logger->emergency('test.emergency');
// Wont see these next two, they're put in buffer, but no CRITICAL+ log triggers them to be sent.
$logger->notice('test.notice will not be in email');
$logger->error('test.notice will not be in email');