✏️ 正在编辑: Log.php
路径:
/srv/systems_dir/biblioteca_yuppie/library/Yuppie/Log.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Yuppie_Log { static private $_dbTable; static private $_log; public static function setDbTable(Zend_Db_Table_Abstract $dbTable) { self::$_dbTable = $dbTable; } public static function getDbTable() { return self::$_dbTable; } public static function update($table, array $dataOld, array $dataNew) { $differences = []; $class = static::class; foreach ($dataOld as $key => $value) { if (array_key_exists($key, $dataNew) && $value != $dataNew[$key] && !(empty($value) && empty($dataNew[$key])) ) { $differences[][$key] = [ 'old' => $value, 'new' => $dataNew[$key] ]; } } if (empty($dataOld)) { foreach ($dataNew as $key => $value) { $differences[][$key] = [ 'old' => "", 'new' => $value ]; } } $logData = [ 'key' => mb_convert_encoding($dataOld && $dataOld['id'] ? $dataOld['id'] : $dataNew['id'], "UTF-8", "auto"), 'username' => mb_convert_encoding(Yuppie_Auth::getIdentity()->login, "UTF-8", "auto"), 'table' => $table, 'endpoint' => $_SERVER['REQUEST_URI'], 'ip' => Yuppie_Core_Util::getClientIp() ]; if (count($differences) > 0) { foreach ($differences as $key => $value) { $logData['data'][] = [ 'field' => key($value), 'usuario' => mb_convert_encoding(Yuppie_Auth::getIdentity()->login, "UTF-8", "auto"), 'campo' => key($value), 'old_data' => mb_convert_encoding($value[key($value)]['old'], "UTF-8", "auto"), 'new_data' => mb_convert_encoding($value[key($value)]['new'], "UTF-8", "auto"), 'chave' => mb_convert_encoding($dataOld && $dataOld['id'] ? $dataOld['id'] : $dataNew['id'], "UTF-8", "auto"), 'tabela' => $table ]; } (new Yuppie_Amazon_Log())->write($logData, $class, 8); } } public static function delete($table, $key) { $class = static::class; $logData = [ 'usuario' => Yuppie_Auth::getIdentity()->login, 'campo' => "excluido", 'new_data' => "registro removido", 'chave' => $key, 'tabela' => $table ]; (new Yuppie_Amazon_Log())->write($logData, $class, 8); } public static function initLog(){ $urlSistema = Yuppie_Auth::getSiteKey(); $writer = new Zend_Log_Writer_Stream("/var/log/sistemayuppie/yuppie_log_{$urlSistema}_" . Zend_Date::now()->get("ddMMyyyy") . ".txt"); self::$_log = new Zend_Log($writer); } public static function write($string, $object = null, $priority = Zend_Log::DEBUG) { self::writeTextLog($string, $object, $priority); // $class = self::class; // if (is_string($object)) { // $class = $object; // } elseif (is_object($object)) { // $class = get_class($object); // } // $dataLog = [ // 'message' => mb_convert_encoding($string, "UTF-8", "auto"), // 'http_referer' => $_SERVER['HTTP_REFERER'] // ]; // (new Yuppie_Amazon_Log())->sendToNewThread($dataLog, $class, $priority); } public static function initTextLog() { $urlSistema = Yuppie_Auth::getSiteKey(); $writer = new Zend_Log_Writer_Stream("/var/log/sistemayuppie/yuppie_log_{$urlSistema}_" . Zend_Date::now()->get("ddMMyyyy") . ".txt"); self::$_log = new Zend_Log($writer); } public static function writeTextLog($string, $object = null, $priority = Zend_Log::DEBUG) { $className = get_class($object); if (self::$_log == null) { self::initTextLog($object); } self::$_log->log('#######################', $priority); self::$_log->log($className, $priority); self::$_log->log($string, $priority); } }
💾 保存文件
← 返回文件管理器