Skip to content

Commit

Permalink
Create Utils.php
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdforst committed Nov 17, 2022
1 parent c3d3ef0 commit ffe5948
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace RRZE\WP;

defined('ABSPATH') || exit;

class Utils
{
public static function debug($input, string $level = 'i')
{
if (!WP_DEBUG) {
return;
}
if (in_array(strtolower((string) WP_DEBUG_LOG), ['true', '1'], true)) {
$logPath = WP_CONTENT_DIR . '/debug.log';
} elseif (is_string(WP_DEBUG_LOG)) {
$logPath = WP_DEBUG_LOG;
} else {
return;
}
if (is_array($input) || is_object($input)) {
$input = print_r($input, true);
}
switch (strtolower($level)) {
case 'e':
case 'error':
$level = 'Error';
break;
case 'i':
case 'info':
$level = 'Info';
break;
case 'd':
case 'debug':
$level = 'Debug';
break;
default:
$level = 'Info';
}
error_log(
date("[d-M-Y H:i:s \U\T\C]")
. " WP $level: "
. basename(__FILE__) . ' '
. $input
. PHP_EOL,
3,
$logPath
);
}
}

0 comments on commit ffe5948

Please sign in to comment.