Elgg  Version master
Cron.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Logger;
4 
15 
21 class Cron extends \Monolog\Logger {
22 
23  protected const CHANNEL = 'CRON';
24 
33  public static function factory(array $params = []): static {
34  $interval = elgg_extract('interval', $params);
35  $cron = _elgg_services()->cron;
36  if (empty($interval) || !in_array($interval, $cron->getConfiguredIntervals(true))) {
37  throw new InvalidArgumentException('Please specify a valid cron interval');
38  }
39 
40  $filename = elgg_extract('filename', $params);
41  if (empty($filename)) {
42  throw new InvalidArgumentException('Please provide a log filename');
43  }
44 
45  $logger = new static(self::CHANNEL);
46 
47  $handler = new StreamHandler($filename);
48 
49  $formatter = new ElggLogFormatter();
50  $formatter->allowInlineLineBreaks();
51  $formatter->ignoreEmptyContextAndExtra();
52 
53  $handler->setFormatter($formatter);
54 
55  $handler->pushProcessor(new MemoryUsageProcessor());
56  $handler->pushProcessor(new MemoryPeakUsageProcessor());
57  $handler->pushProcessor(new ProcessIdProcessor());
58  $handler->pushProcessor(new TagProcessor([$interval]));
59  $handler->pushProcessor(new PsrLogMessageProcessor());
60 
61  $logger->pushHandler($handler);
62 
63  return $logger;
64  }
65 }
Custom log formatter.
Exception thrown if an argument is not of the expected type.
$params
Saves global plugin settings.
Definition: save.php:13
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
const CHANNEL
Definition: Cron.php:23
Custom logger for an individual cron interval.
Definition: Cron.php:21
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
static factory(array $params=[])
Definition: Cron.php:33
$handler
Definition: add.php:7