public function handle($request, Closure $next) { $debug = env('APP_DEBUG', true); $appEnv = env('APP_ENV', 'local'); if (isHttps()) { $_SERVER['HTTPS'] = 'on'; } if ($debug && ($appEnv === 'local' || $appEnv === 'dev')) { #Enable writing pkdebug to log file PkLibConfig::setSuppressPkDebug(false); $logDir = realpath(storage_path() . '/logs'); $logPath = $logDir . '/pkapp.log'; appLogPath($logPath); } return $next($request); }
function setAppLog() { PkLibConfig::setSuppressPkDebug(false); $logDir = realpath(storage_path().'/logs'); $logPath = $logDir.'/pkapp.log'; appLogPath($logPath); }
/** Outputs to the destination specified by $useDebugLog * * @staticvar boolean $first * @param type $str * @return boolean * @throws Exception */ function pkdebugOut($str, $logpath = null) { //PkLibConfig::$isWarning = 1; if ($logpath) error_log("Logpath is: [$logpath]"); static $first = true; if ($logpath) $reset = false; else $reset = appLogReset(); //if ($reset) { try { //$logpath = $_SERVER['DOCUMENT_ROOT'].'/../app/logs/app.log'; //$logpath = WP_CONTENT_DIR.'/app.log'; //$logpath = $_SERVER['DOCUMENT_ROOT'] . '/logs/app.log'; if (!$logpath) $logpath = appLogPath(); if (PkLibConfig::$isWarning) { if (PkLibConfig::$warnLogDir) { $warnpath = PkLibConfig::$warnLogDir . '/' . PkLibConfig::$warnLogName; } else { $warnpath = getAppLogDir() . '/' . PkLibConfig::$warnLogName; } $fp = fopen($warnpath, 'a+'); if (!$fp) { throw new Exception("Failed to open Warning Log [$warnpath] for writing"); } fwrite($fp, $str); fclose($fp); } if ($first && $reset) { $first = false; $fp = fopen($logpath, 'w+'); } else { $fp = fopen($logpath, 'a+'); } if (!$fp) throw new Exception("Failed to open DebugLog [$logpath] for writing"); fwrite($fp, $str); fclose($fp); } catch (Exception $e) { error_log("Error Writing to Debug Log: " . $e); return false; } //} else { // error_log($str); //} return true; }