Removed useless ability to write to a log file; other minor changes

This commit is contained in:
pezcurrel 2023-01-06 17:05:47 +01:00
parent b22befdec2
commit 662e789bbf

View file

@ -53,11 +53,10 @@ $opts=[
'fetchusers'=>false,
'udiratts'=>5,
'udirfailst'=>90,
'logminmsglev'=>1,
'tuiminmsglev'=>1
'minmsgimplev'=>1
];
$msglevs=['debug', 'info', 'warning', 'error', 'none'];
$msglevs=['Debug', 'Info', 'Warning', 'Error', 'None'];
$ghtsa=[[' day',' days'],[' hour',' hours'],[' minute',' minutes'],[' second',' seconds']];
@ -95,18 +94,14 @@ OPTIONS
DEFAULT: '.ght($opts['timeout'],$ghtsa).'
-d, --dryrun
If this option is set, the script wont write anything in the database.
-L, --logminmsglev <«debug»|«info»|«warning»|«error»|«none»>
Defines the minimum “importance level” of messages to be written into the
log file «run/[instance hostname].log». There are 4 “importance levels”, in
this order of importance: «debug», «info», «warning», «error».
Setting this option to any of these values will write into the logfile all
the messages with the specified or a greater level; setting it to the
special value «none» will completely disable logging to file.
DEFAULT: '.$msglevs[$opts['logminmsglev']].'
-T, --tuiminmsglev <«debug»|«info»|«warning»|«error»|«none»>
-m, --minmsgimplev <«debug»|«info»|«warning»|«error»|«none»>
Defines the minimum “importance level” of messages to be written to the
terminal. See the option above to understand how this works.
DEFAULT: '.$msglevs[$opts['tuiminmsglev']].'
text user interface. There are 4 “importance levels”, in this order of
importance: «debug», «info», «warning», «error». Setting this option to any
of these values will make the script write to the text user interface all
the messages with the specified or a greater level; setting it to the
special value «none» will completely disable messages.
DEFAULT: '.lcfirst($msglevs[$opts['minmsgimplev']]).'
-h, --help
If this option is set, the script will show this help text and exit.
@ -148,16 +143,11 @@ for ($i=1; $i<$argc; $i++) {
$opts['ldtoots']=$argv[$i]+0;
} elseif ($argv[$i]=='-d' || $argv[$i]=='--dryrun') {
$opts['dryrun']=true;
} elseif ($argv[$i]=='-L' || $argv[$i]=='--logminmsglev') {
if ($i+1>=$argc || !in_array(strtolower($argv[$i+1]),$msglevs))
} elseif ($argv[$i]=='-m' || $argv[$i]=='--minmsgimplev') {
if ($i+1>=$argc || !in_array(ucfirst(strtolower($argv[$i+1])),$msglevs))
mexit('option «'.$argv[$i].'» requires a “message importance level” value as an argument (use «-h» to read help).'.N,1);
$i++;
$opts['logminmsglev']=array_search(strtolower($argv[$i]),$msglevs);
} elseif ($argv[$i]=='-T' || $argv[$i]=='--tuiminmsglev') {
if ($i+1>=$argc || !in_array(strtolower($argv[$i+1]),$msglevs))
mexit('option «'.$argv[$i].'» requires a “message importance level” value as an argument (use «-h» to read help).'.N,1);
$i++;
$opts['tuiminmsglev']=array_search(strtolower($argv[$i]),$msglevs);
$opts['minmsgimplev']=array_search(ucfirst(strtolower($argv[$i])),$msglevs);
} elseif ($argv[$i]=='-h' || $argv[$i]=='--help') {
echo($help);
exit(0);
@ -170,8 +160,6 @@ for ($i=1; $i<$argc; $i++) {
if (is_null($opts['hostname'])) mexit('you didnt specify an hostname (you can read the help text using «-h» or «--help»).'.N,1);
foreach ($msglevs as $key=>$val) $msglevs[$key]=ucfirst($val);
$inifp=__DIR__.'/../conf/mustard.ini';
$iniarr=@parse_ini_file($inifp)
or mexit('could not open config file «'.$inifp.'»'.N,1);
@ -195,12 +183,6 @@ $mastodons=implode('|',$mastodons);
$tables=tables($link);
//print_r($tables);
if ($opts['logminmsglev']<4) {
$logfp=__DIR__.'/run/'.$opts['hostname'].'.gii.log';
$logf=@fopen($logfp,'w');
if ($logf===false) mexit('could not open file «'.$logfp.'» in write mode.'.N,1);
}
$instints=['ID', 'FirstSeen', 'IsMastodon', 'Priority', 'Visible', 'Noxious', 'NoxLastModTS', 'LocalityID', 'OurLangsLock', 'UserCount', 'StatusCount', 'DomainCount', 'ActiveUsersMonth', 'ActiveUsersHalfYear', 'RegOpen', 'RegReqApproval', 'MaxTootChars', 'AdmCreatedAt', 'WasLastCheckOk', 'LastOkCheckTS', 'GuestID', 'LastGuestEdit', 'InsertTS', 'RPos'];
$idata=[];
@ -914,28 +896,26 @@ function myq(&$link,$query,$line) {
}
function eecho($lev,$msg) {
global $logf, $opts, $msglevs;
global $opts, $msglevs;
$time=microtime(false);
$time=explode(' ',$time);
$time=date('Y-m-d H:i:s',$time[1]).'.'.substr($time[0],2);
$msg=$time.' '.$msglevs[$lev].': '.$msg;
if ($lev>=$opts['tuiminmsglev']) {
if ($lev>=$opts['minmsgimplev']) {
if ($lev<2)
echo($msg);
else
fwrite(STDERR,$msg);
}
if ($lev>=$opts['logminmsglev'] && isset($logf) && $logf!==false) fwrite($logf,$msg);
}
function mexit($msg,$code) {
global $link, $logf;
global $link;
if (isset($link) && $link!==false) mysqli_close($link);
if ($code!=0)
eecho(3,$msg);
else
eecho(1,$msg);
if (isset($logf) && $logf!==false) fclose($logf);
exit($code);
}