Jake Vanderwerf
8 days ago 90f5c3069f23f63036ab0178ff9ab69effcfb2ea
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
40
41
42
<?php
namespace JVBase\managers;
 
use JVBase\Instance;
use WP_Error;
use Exception;
use WP_REST_Request;
 
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
 
class Errors
{
    use Instance;
 
    /**
     * @param string $message
     * @param array $context
     * @return void
     */
    public static function log(string $message, array $context = []):void
    {
        $msg = '{'.BASE.'}';
        if (array_key_exists('class', $context)) {
            $msg .= '['.$context['class'].']';
            unset($context['class']);
        }
        if (array_key_exists('method', $context)) {
            $msg .= '::'.$context['method'];
            unset($context['method']);
        }
        if (array_key_exists('function', $context)) {
            $msg .= $context['function'];
            unset($context['function']);
        }
        error_log($msg.' '.$message);
        if (!empty($context)) {
            error_log('Context: '.print_r($context, true));
        }
    }
}