76 lines
1.2 KiB
PHP
76 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace alveolata\log;
|
||
|
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
class enum_level
|
||
|
{
|
||
|
public const error = 0;
|
||
|
public const warning = 1;
|
||
|
public const notice = 2;
|
||
|
public const info = 3;
|
||
|
public const debug = 4;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author Christian Fraß <frass@greenscale.de>
|
||
|
*/
|
||
|
function level_decode(
|
||
|
string $level
|
||
|
) : int
|
||
|
{
|
||
|
$map = [
|
||
|
'error' => 0,
|
||
|
'warning' => 1,
|
||
|
'notice' => 2,
|
||
|
'info' => 3,
|
||
|
'debug' => 4,
|
||
|
];
|
||
|
if (! \array_key_exists($level, $map)) {
|
||
|
throw (new \Exception(\sprintf('unhandled log level "%s"', $level)));
|
||
|
}
|
||
|
else {
|
||
|
// return \alveolata\string\pad_right(\alveolata\string\case_upper($map[$level]), 7, ' ');
|
||
|
return $map[$level];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param int $level
|
||
|
* @return string
|
||
|
* @author Christian Fraß <frass@greenscale.de>
|
||
|
*/
|
||
|
function level_encode(
|
||
|
int $level
|
||
|
) : string
|
||
|
{
|
||
|
$map = [
|
||
|
0 => 'error',
|
||
|
1 => 'warning',
|
||
|
2 => 'notice',
|
||
|
3 => 'info',
|
||
|
4 => 'debug',
|
||
|
];
|
||
|
if (! \array_key_exists($level, $map)) {
|
||
|
throw (new \Exception(sprintf('unhandled log output level %u', $level)));
|
||
|
}
|
||
|
else {
|
||
|
// return \alveolata\string\pad_right(\alveolata\string\case_upper($map[$level]), 7, ' ');
|
||
|
return $map[$level];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @deprecated
|
||
|
*/
|
||
|
function output_translate_level($level) {
|
||
|
return level_encode($level);
|
||
|
}
|
||
|
|
||
|
?>
|