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: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147:
<?php
namespace Kernel\Dispatch;
use Core\Providers\Config;
use Core\Helpers\Hooks;
class Logger {
private static $instance = FALSE;
protected static $hooks;
public static function singleton() {
if (!self::$instance) {
$v = __CLASS__;
self::$instance = new $v;
}
return self::$instance;
}
public function __construct() {
self::$hooks = $GLOBALS['hooks'];
}
public static function info($message, $errType = 0) {
$debug = debug_backtrace();
$file = $debug[0]['file'];
$line = $debug[0]['line'];
if (!(is_string($message) || is_numeric($message))) {
$message = var_export($message, TRUE);
}
self::sendLog('info', $file, $line, $message, $errType);
}
public static function warn($message, $errType = 0) {
$debug = debug_backtrace();
$file = $debug[0]['file'];
$line = $debug[0]['line'];
if (!(is_string($message) || is_int($message))) {
$message = var_export($message, TRUE);
}
self::sendLog('warn', $file, $line, $message, $errType);
}
public static function error ($error) {
$errType = $error["type"];
$file = $error["file"];
$line = $error["line"];
$message = $error["message"];
self::sendLog('error', $file, $line, $message, $errType);
}
protected static function sendLog ($type, $file, $line, $message, $errType) {
$config = Config::singleton()->load('config.ini');
if ($config->get('Log', 'LOG_ENABLED') == '0') {
return;
}
$id = __ID__;
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$method = $_SERVER['REQUEST_METHOD'] ?: 'GET';
$accept = !empty($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : 'robot';
$userAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'robot';
$token = $config->get('Log', 'TOKEN');
$postArray = array(
'type' => $type,
'file' => $file,
'line' => $line,
'mssg' => $message,
'errtype' => $errType,
'id' => $id,
'url' => $url,
'method' => $method,
'accept' => $accept,
'userag' => $userAgent,
'token' => $token
);
$post = http_build_query($postArray);
self::$hooks->do_action('logger_post', $postArray);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config->get('Log', 'URL'));
curl_setopt($ch, CURLOPT_POST, count($postArray));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$r = curl_exec($ch);
curl_close($ch);
if (class_exists('\FB')) {
if ($type == 'error') {
\FB::error($r);
} elseif ($type == 'warn') {
\FB::warn($r);
} else {
\FB::info($r);
}
}
}
}