-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLogRecord.php
More file actions
39 lines (30 loc) · 955 Bytes
/
LogRecord.php
File metadata and controls
39 lines (30 loc) · 955 Bytes
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
<?php declare( strict_types = 1 );
namespace PiotrPress\Logger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LogLevel;
class LogRecord {
private $level;
private $message;
private $context;
public function __construct( string $level, string $message, array $context = [] ) {
if( ! self::isLevel( $level ) )
throw new InvalidArgumentException( 'Unknown log level: ' . $level );
$this->level = $level;
$this->message = $message;
$this->context = $context;
}
static public function isLevel( $level ) : bool {
$class = LogLevel::class;
$const = \strtoupper( $level );
return \defined( "{$class}::{$const}" );
}
public function getLevel() : string {
return $this->level;
}
public function getMessage() : string {
return $this->message;
}
public function getContext() : array {
return $this->context;
}
}