-
-
Save thinkstylestudio/6169288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// No trailing slash | |
define('BURST_LOG_PATH', ABSPATH . 'wp-content'); | |
// Define which get logged in Burst::$_burst_log_levels | |
define('BURST_INFO', 1); | |
define('BURST_DEBUG', 2); | |
define('BURST_CRITICAL', 3); | |
if (!class_exists('Burst')) { | |
class Burst { | |
protected static $_burst_log_levels = array(BURST_INFO, | |
BURST_DEBUG, | |
BURST_CRITICAL); | |
protected static $_default_log_file = 'burst.log'; | |
public static function log($message, $level=BURST_DEBUG, $file=null, $force=false) { | |
if (!in_array($level, self::$_burst_log_levels) && $force == false) { | |
return false; | |
} else { | |
$filename = ($file === null) ? self::$_default_log_file : $file; | |
$filename = BURST_LOG_PATH . '/' . $filename; | |
$log_level_phrase = ($level == 1) ? "INFO " : (($level == 2) ? "DEBUG" : "CRIT "); | |
// print_r if message is an object or array | |
$message = (is_array($message) || is_object($message)) ? print_r($message, true) : $message; | |
$formatted_message = sprintf('%s %s (%d): %s', | |
date('c') /* Timestamp */, | |
$log_level_phrase /* Log Level Phrase */, | |
(int) $level /* Log Level Number */, | |
$message /* Log Message */) . PHP_EOL; | |
$file_write = @file_put_contents($filename, $formatted_message, FILE_APPEND); | |
if ($file_write === false) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
} | |
public static function log_environment($level=BURST_DEBUG, $file='burst.env.log') { | |
self::log(json_encode($_SERVER), $level, $file); | |
self::log(json_encode($_REQUEST), $level, $file); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment