fixes to support composer / packagist

This commit is contained in:
Joey Kimsey
2024-08-08 01:18:19 -04:00
parent 0627207452
commit bfe714b179
6 changed files with 67 additions and 18 deletions

View File

@ -1,108 +0,0 @@
<?php
/**
* logger.php
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
*/
namespace TheTempusProject\Canary\Classes;
use TheTempusProject\Bedrock\Functions\Date;
class Logger {
public $file;
public $logDirectory;
public $logFilePath;
public function __construct() {
$this->setupLogFile();
$this->file = fopen( $this->logFilePath, 'a' );
fwrite( $this->file, '===================------++++++++++------===================' . PHP_EOL );
}
public function setupLogFile() {
$this->logDirectory = rtrim( CANARY_DEBUG_DIRECTORY, DIRECTORY_SEPARATOR );
if ( ! is_dir( $this->logDirectory ) ) {
mkdir( $this->logDirectory, 0777, true );
}
$currentFile = date('m-d-Y') . '.log';
$this->logFilePath = $this->logDirectory . DIRECTORY_SEPARATOR . $currentFile;
if ( ! file_exists( $this->logFilePath ) ) {
touch( $this->logFilePath );
chmod( $this->logFilePath, 0777 );
}
}
public function __destruct() {
fwrite( $this->file, '============================================================' . PHP_EOL );
fclose( $this->file );
}
public function addLog( $type = 'log', $log ) {
switch ( CANARY_DEBUG_TO_FILE_LEVEL ) {
case CANARY_DEBUG_LEVEL_ERROR:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_WARN:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_INFO:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
CANARY_DEBUG_LEVEL_INFO,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_LOG:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
CANARY_DEBUG_LEVEL_INFO,
CANARY_DEBUG_LEVEL_LOG,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_DEBUG:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
CANARY_DEBUG_LEVEL_INFO,
CANARY_DEBUG_LEVEL_LOG,
CANARY_DEBUG_LEVEL_DEBUG,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
default:
return;
}
$formattedMessage = $this->timestamp() . $this->typestamp( $type ) . $log . PHP_EOL;
fwrite( $this->file, $formattedMessage );
}
private function timestamp() {
$dateString = Date::getReadableDate( time() );
return '['.$dateString.'] - ';
}
private function typestamp( $type ) {
$dateString = Date::getReadableDate( time() );
return '[' . strtoupper( $type ) . '] - ';
}
}