Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dc9b831534 | ||
![]() |
49bb26a063 | ||
![]() |
9958bdd205 | ||
![]() |
0507fbb9d1 | ||
![]() |
808baec53c | ||
![]() |
284cd4f52a | ||
![]() |
359afdcbe0 |
5 changed files with 56 additions and 12 deletions
30
CHANGELOG.md
30
CHANGELOG.md
|
@ -5,6 +5,36 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.0.7] - 2025-01-13
|
||||||
|
|
||||||
|
This update introduces a minor fix
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed FileLogging issue by setting the write permission to 0666 for the log file if it doesn't exist.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.0.6] - 2025-01-10
|
||||||
|
|
||||||
|
This update introduces a minor change
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- File logging is disabled for web environments due to instability in file locking, until a better solution is found.
|
||||||
|
|
||||||
|
|
||||||
|
## [2.0.5] - 2025-01-09
|
||||||
|
|
||||||
|
This update introduces a minor bug fix
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Refactor file locking to return status and handle failure.
|
||||||
|
|
||||||
|
|
||||||
|
## [2.0.4] - 2024-12-04
|
||||||
|
|
||||||
|
This update introduces a minor bug fix
|
||||||
|
|
||||||
|
|
||||||
## [2.0.3] - 2024-11-05
|
## [2.0.3] - 2024-11-05
|
||||||
|
|
||||||
This update introduces a minor bug fix
|
This update introduces a minor bug fix
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
"package": "net.nosial.loglib",
|
"package": "net.nosial.loglib",
|
||||||
"company": "Nosial",
|
"company": "Nosial",
|
||||||
"copyright": "Copyright (c) 2022-2023 Nosial",
|
"copyright": "Copyright (c) 2022-2023 Nosial",
|
||||||
"version": "2.0.3",
|
"version": "2.0.7",
|
||||||
"uuid": "de1deca6-7b65-11ed-a8b0-a172264634d8"
|
"uuid": "de1deca6-7b65-11ed-a8b0-a172264634d8"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
|
|
@ -32,8 +32,11 @@
|
||||||
// Create the file if it doesn't exist
|
// Create the file if it doesn't exist
|
||||||
if (!file_exists($filePath))
|
if (!file_exists($filePath))
|
||||||
{
|
{
|
||||||
$this->fileHandle = fopen($filePath, 'w');
|
// Create the file
|
||||||
fclose($this->fileHandle);
|
touch($filePath);
|
||||||
|
|
||||||
|
// Set the file permissions to 0666
|
||||||
|
chmod($filePath, 0666);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +45,12 @@
|
||||||
*
|
*
|
||||||
* @throws RuntimeException if unable to open or lock the file.
|
* @throws RuntimeException if unable to open or lock the file.
|
||||||
*/
|
*/
|
||||||
private function lock(): void
|
private function lock(): bool
|
||||||
{
|
{
|
||||||
$this->fileHandle = fopen($this->filePath, 'a');
|
$this->fileHandle = @fopen($this->filePath, 'a');
|
||||||
if ($this->fileHandle === false)
|
if ($this->fileHandle === false)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Unable to open the file: " . $this->filePath);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep trying to acquire the lock until it succeeds
|
// Keep trying to acquire the lock until it succeeds
|
||||||
|
@ -64,6 +67,8 @@
|
||||||
flock($this->fileHandle, LOCK_UN);
|
flock($this->fileHandle, LOCK_UN);
|
||||||
$this->lock();
|
$this->lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +92,11 @@
|
||||||
*/
|
*/
|
||||||
public function append(string $data): void
|
public function append(string $data): void
|
||||||
{
|
{
|
||||||
$this->lock();
|
if(!$this->lock())
|
||||||
|
{
|
||||||
|
// Do not proceed if the file cannot be locked
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->fileHandle !== false)
|
if ($this->fileHandle !== false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,6 @@ class ConsoleLogging implements LogHandlerInterface
|
||||||
*/
|
*/
|
||||||
public static function handle(Application $application, Event $event): void
|
public static function handle(Application $application, Event $event): void
|
||||||
{
|
{
|
||||||
// Check if the application is running in a CLI environment, if not, return
|
|
||||||
if(!Utilities::runningInCli())
|
if(!Utilities::runningInCli())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -208,7 +207,10 @@ class ConsoleLogging implements LogHandlerInterface
|
||||||
print('Stack Trace:' . PHP_EOL);
|
print('Stack Trace:' . PHP_EOL);
|
||||||
foreach($trace as $item)
|
foreach($trace as $item)
|
||||||
{
|
{
|
||||||
print( ' - ' . self::color($item['file'], ConsoleColors::RED) . ':' . $item['line'] . PHP_EOL);
|
if(isset($item['file']) && isset($item['line']))
|
||||||
|
{
|
||||||
|
print( ' - ' . self::color($item['file'], ConsoleColors::RED) . ':' . $item['line'] . PHP_EOL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,9 +88,9 @@ class FileLogging implements LogHandlerInterface
|
||||||
|
|
||||||
$logging_file = $logging_directory . DIRECTORY_SEPARATOR . Utilities::sanitizeFileName($application->getApplicationName()) . '-' . date('Y-m-d') . '.log';
|
$logging_file = $logging_directory . DIRECTORY_SEPARATOR . Utilities::sanitizeFileName($application->getApplicationName()) . '-' . date('Y-m-d') . '.log';
|
||||||
|
|
||||||
if(!file_exists($logging_file))
|
if(!file_exists($logging_file) && !@touch($logging_file))
|
||||||
{
|
{
|
||||||
touch($logging_file);
|
throw new RuntimeException(sprintf("Cannot write to %s due to insufficient permissions", $logging_file));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $logging_file;
|
return $logging_file;
|
||||||
|
@ -133,7 +133,10 @@ class FileLogging implements LogHandlerInterface
|
||||||
$output .= 'Stack Trace:' . PHP_EOL;
|
$output .= 'Stack Trace:' . PHP_EOL;
|
||||||
foreach($trace as $item)
|
foreach($trace as $item)
|
||||||
{
|
{
|
||||||
$output .= ' - ' . $item['file'] . ':' . $item['line'] . PHP_EOL;
|
if(isset($item['file']) && isset($item['line']))
|
||||||
|
{
|
||||||
|
$output .= ' - ' . $item['file'] . ':' . $item['line'] . PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue