Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7437813
ElasticaFormatter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ElasticaFormatter.php
View Options
<?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
;
use
Elastica\Document
;
/**
* Format a log message into an Elastica Document
*
* @author Jelle Vink <jelle.vink@gmail.com>
*
* @phpstan-import-type Record from \Monolog\Logger
*/
class
ElasticaFormatter
extends
NormalizerFormatter
{
/**
* @var string Elastic search index name
*/
protected
$index
;
/**
* @var ?string Elastic search document type
*/
protected
$type
;
/**
* @param string $index Elastic Search index name
* @param ?string $type Elastic Search document type, deprecated as of Elastica 7
*/
public
function
__construct
(
string
$index
,
?
string
$type
)
{
// elasticsearch requires a ISO 8601 format date with optional millisecond precision.
parent
::
__construct
(
'Y-m-d
\T
H:i:s.uP'
);
$this
->
index
=
$index
;
$this
->
type
=
$type
;
}
/**
* {@inheritDoc}
*/
public
function
format
(
array
$record
)
{
$record
=
parent
::
format
(
$record
);
return
$this
->
getDocument
(
$record
);
}
public
function
getIndex
():
string
{
return
$this
->
index
;
}
/**
* @deprecated since Elastica 7 type has no effect
*/
public
function
getType
():
string
{
/** @phpstan-ignore-next-line */
return
$this
->
type
;
}
/**
* Convert a log message into an Elastica Document
*
* @phpstan-param Record $record
*/
protected
function
getDocument
(
array
$record
):
Document
{
$document
=
new
Document
();
$document
->
setData
(
$record
);
if
(
method_exists
(
$document
,
'setType'
))
{
/** @phpstan-ignore-next-line */
$document
->
setType
(
$this
->
type
);
}
$document
->
setIndex
(
$this
->
index
);
return
$document
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 14:12 (5 h, 36 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
92/51/c9961353818cb11dc16c783e244b
Default Alt Text
ElasticaFormatter.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment