1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 10:49:36 +02:00
This commit is contained in:
Daniel Neto 2024-03-15 10:06:31 -03:00
parent 8664fb0162
commit 3c385d4dd7
2 changed files with 134 additions and 125 deletions

View file

@ -3910,130 +3910,6 @@ function isOldChromeVersion()
return false;
}
function TimeLogStart($name)
{
global $global;
if (!empty($global['noDebug'])) {
return false;
}
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
if (empty($global['start']) || !is_array($global['start'])) {
$global['start'] = [];
}
$global['start'][$name] = $time;
return $name;
}
function TimeLogEnd($name, $line, $TimeLogLimit = 0.7) {
global $global;
if (!empty($global['noDebug']) || empty($global['start'][$name])) {
return false;
}
if (!empty($global['TimeLogLimit'])) {
$TimeLogLimit = $global['TimeLogLimit'];
}
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $global['start'][$name]), 4);
$type = AVideoLog::$DEBUG;
$backtrace = '';
$ua = '';
if (empty($global['noDebugSlowProcess']) && $total_time > $TimeLogLimit) {
if ($total_time > 1) {
$type = AVideoLog::$WARNING;
}
if ($total_time > 2) {
$type = AVideoLog::$ERROR;
$backtrace = ' backtrace=' . json_encode(debug_backtrace());
}
$ua = ' IP='.getRealIpAddr();
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
if(isBot()){
$ua .= " BOT ";
$ua .= " USER_AGENT={$_SERVER['HTTP_USER_AGENT']}";
}
}else{
$ua .= " USER_AGENT=Undefined server=".json_encode($_SERVER);
}
_error_log("Time: ". str_pad(number_format($total_time,3) . "s", 8) . " | Limit: {$TimeLogLimit}s | Location: {$_SERVER["SCRIPT_FILENAME"]} Line {$line} [{$name}]{$ua}{$backtrace}", $type);
}
TimeLogStart($name);
}
class AVideoLog
{
public static $DEBUG = 0;
public static $WARNING = 1;
public static $ERROR = 2;
public static $SECURITY = 3;
public static $SOCKET = 4;
}
function _error_log_debug($message, $show_args = false)
{
$array = debug_backtrace();
$message .= PHP_EOL;
foreach ($array as $value) {
$message .= "function: {$value['function']} Line: {{$value['line']}} File: {{$value['file']}}" . PHP_EOL;
if ($show_args) {
$message .= print_r($value['args'], true) . PHP_EOL;
}
}
_error_log(PHP_EOL . '***' . PHP_EOL . $message . '***');
}
function _error_log($message, $type = 0, $doNotRepeat = false)
{
if (empty($doNotRepeat)) {
// do not log it too many times when you are using HLS format, other wise it will fill the log file with the same error
$doNotRepeat = preg_match("/hls.php$/", $_SERVER['SCRIPT_NAME']);
}
if ($doNotRepeat) {
return false;
}
global $global;
if (!empty($global['noDebug']) && $type == 0) {
return false;
}
if (!is_string($message)) {
$message = json_encode($message);
}
$prefix = "AVideoLog::";
switch ($type) {
case AVideoLog::$DEBUG:
$prefix .= "DEBUG: ";
break;
case AVideoLog::$WARNING:
$prefix .= "WARNING: ";
break;
case AVideoLog::$ERROR:
$prefix .= "ERROR: ";
break;
case AVideoLog::$SECURITY:
$prefix .= "SECURITY: ";
break;
case AVideoLog::$SOCKET:
$prefix .= "SOCKET: ";
break;
}
$str = $prefix . $message . " SCRIPT_NAME: {$_SERVER['SCRIPT_NAME']}";
/*
if (isCommandLineInterface() && empty($global['doNotPrintLogs'])) {
echo '[' . date('Y-m-d H:i:s') . '] ' . $str . PHP_EOL;
}
*/
error_log($str);
}
function postVariables($url, $array, $httpcodeOnly = true, $timeout = 10)
{
if (!$url || !is_string($url) || !preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url)) {
@ -10261,3 +10137,4 @@ require_once __DIR__.'/functionMySQL.php';
require_once __DIR__.'/functionDocker.php';
require_once __DIR__.'/functionImages.php';
require_once __DIR__.'/functionExec.php';
require_once __DIR__.'/functionsLogs.php';

132
objects/functionsLogs.php Normal file
View file

@ -0,0 +1,132 @@
<?php
function TimeLogStart($name)
{
global $global;
if (!empty($global['noDebug'])) {
return false;
}
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
if (empty($global['start']) || !is_array($global['start'])) {
$global['start'] = [];
}
$global['start'][$name] = $time;
return $name;
}
function TimeLogEnd($name, $line, $TimeLogLimit = 0.7) {
global $global;
if (!empty($global['noDebug']) || empty($global['start'][$name])) {
return false;
}
if (!empty($global['TimeLogLimit'])) {
$TimeLogLimit = $global['TimeLogLimit'];
}
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $global['start'][$name]), 4);
$type = AVideoLog::$DEBUG;
$backtrace = '';
$ua = '';
if (empty($global['noDebugSlowProcess']) && $total_time > $TimeLogLimit) {
if ($total_time > 1) {
$type = AVideoLog::$WARNING;
}
if ($total_time > 2) {
$type = AVideoLog::$ERROR;
$backtrace = ' backtrace=' . json_encode(debug_backtrace());
}
$ua = ' IP='.getRealIpAddr();
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
if(isBot()){
$ua .= " BOT ";
$ua .= " USER_AGENT={$_SERVER['HTTP_USER_AGENT']}";
}
}else{
$ua .= " USER_AGENT=Undefined server=".json_encode($_SERVER);
}
_error_log("Time: ". str_pad(number_format($total_time,3) . "s", 8) . " | Limit: {$TimeLogLimit}s | Location: {$_SERVER["SCRIPT_FILENAME"]} Line {$line} [{$name}]{$ua}{$backtrace}", $type);
}
TimeLogStart($name);
}
class AVideoLog
{
public static $DEBUG = 0;
public static $WARNING = 1;
public static $ERROR = 2;
public static $SECURITY = 3;
public static $SOCKET = 4;
}
function _error_log_debug($message, $show_args = false)
{
$array = debug_backtrace();
$message .= PHP_EOL;
foreach ($array as $value) {
$message .= "function: {$value['function']} Line: {{$value['line']}} File: {{$value['file']}}" . PHP_EOL;
if ($show_args) {
$message .= print_r($value['args'], true) . PHP_EOL;
}
}
_error_log(PHP_EOL . '***' . PHP_EOL . $message . '***');
}
function _error_log($message, $type = 0, $doNotRepeat = false)
{
if(isSchedulerRun()){
return false;
}
if (empty($doNotRepeat)) {
// do not log it too many times when you are using HLS format, other wise it will fill the log file with the same error
$doNotRepeat = preg_match("/hls.php$/", $_SERVER['SCRIPT_NAME']);
}
if ($doNotRepeat) {
return false;
}
global $global;
if (!empty($global['noDebug']) && $type == 0) {
return false;
}
if (!is_string($message)) {
$message = json_encode($message);
}
$prefix = "AVideoLog::";
switch ($type) {
case AVideoLog::$DEBUG:
$prefix .= "DEBUG: ";
break;
case AVideoLog::$WARNING:
$prefix .= "WARNING: ";
break;
case AVideoLog::$ERROR:
$prefix .= "ERROR: ";
break;
case AVideoLog::$SECURITY:
$prefix .= "SECURITY: ";
break;
case AVideoLog::$SOCKET:
$prefix .= "SOCKET: ";
break;
}
$str = $prefix . $message . " SCRIPT_NAME: {$_SERVER['SCRIPT_NAME']}";
/*
if (isCommandLineInterface() && empty($global['doNotPrintLogs'])) {
echo '[' . date('Y-m-d H:i:s') . '] ' . $str . PHP_EOL;
}
*/
error_log($str);
}
function isSchedulerRun(){
return preg_match('/Scheduler\/run\.php$/', $_SERVER['SCRIPT_NAME']);
}