friendica-addons/monolog/vendor/monolog/monolog/src/Monolog/Formatter/LogmaticFormatter.php

67 lines
1.4 KiB
PHP
Raw Normal View History

2022-10-17 21:25:03 +02:00
<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Formatter;
/**
* Encodes message information into JSON in a format compatible with Logmatic.
*
* @author Julien Breux <julien.breux@gmail.com>
*/
class LogmaticFormatter extends JsonFormatter
{
protected const MARKERS = ["sourcecode", "php"];
2023-01-18 00:17:49 +01:00
/**
* @var string
*/
protected $hostname = '';
2022-10-17 21:25:03 +02:00
2023-01-18 00:17:49 +01:00
/**
* @var string
*/
protected $appname = '';
2022-10-17 21:25:03 +02:00
public function setHostname(string $hostname): self
{
$this->hostname = $hostname;
return $this;
}
2023-01-18 00:17:49 +01:00
public function setAppname(string $appname): self
2022-10-17 21:25:03 +02:00
{
2023-01-18 00:17:49 +01:00
$this->appname = $appname;
2022-10-17 21:25:03 +02:00
return $this;
}
/**
* Appends the 'hostname' and 'appname' parameter for indexing by Logmatic.
*
* @see http://doc.logmatic.io/docs/basics-to-send-data
* @see \Monolog\Formatter\JsonFormatter::format()
*/
2023-01-18 00:17:49 +01:00
public function format(array $record): string
2022-10-17 21:25:03 +02:00
{
2023-01-18 00:17:49 +01:00
if (!empty($this->hostname)) {
2022-10-17 21:25:03 +02:00
$record["hostname"] = $this->hostname;
}
2023-01-18 00:17:49 +01:00
if (!empty($this->appname)) {
$record["appname"] = $this->appname;
2022-10-17 21:25:03 +02:00
}
$record["@marker"] = static::MARKERS;
2023-01-18 00:17:49 +01:00
return parent::format($record);
2022-10-17 21:25:03 +02:00
}
}