Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit a8c347f

Browse files
committed
- Logs split up for every day
1 parent d843f73 commit a8c347f

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

app/Exceptions/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function report(Throwable $exception)
4545
return;
4646
}
4747

48-
$log = storage_path('logs/error.log');
48+
$log = storage_path('logs/error-' . date('Y-m-d') . '.log');
4949
$timestamp = date(\DateTimeInterface::RFC3339);
5050
$trace = $exception->getTrace();
5151
$stack = [];

app/Helpers/LoggingHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ public static function log(string $sessionKey, string $msg)
100100
private static function init()
101101
{
102102
if (self::$logFile === null) {
103-
self::$logFile = rtrim(storage_path('logs'), '/\\') . '/op-fw.log';
103+
self::$logFile = rtrim(storage_path('logs'), '/\\') . '/op-fw-' . date('Y-m-d') . '.log';
104104
}
105105
if (self::$accessLogFile === null) {
106-
self::$accessLogFile = rtrim(storage_path('logs'), '/\\') . '/op-fw-access.log';
106+
self::$accessLogFile = rtrim(storage_path('logs'), '/\\') . '/op-fw-access-' . date('Y-m-d') . '.log';
107107
}
108108

109109
self::registerShutdown();

routes/web.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,23 @@
108108
});
109109

110110
// Used to get logs.
111-
Route::get('/op-logs/{type}/{api_key}', function (string $type, string $api_key) {
111+
Route::get('/op-logs/{type}/{api_key}/{date?}', function (string $type, string $api_key, string $date = '') {
112+
if (!$date) {
113+
$date = date('Y-m-d');
114+
} else {
115+
$date = preg_replace('/[^\d-]/m', '', $date);
116+
}
117+
112118
$file = '';
113119
switch ($type) {
114120
case 'default':
115-
$file = storage_path('logs/op-fw.log');
121+
$file = storage_path('logs/op-fw-' . $date . '.log');
116122
break;
117123
case 'access':
118-
$file = storage_path('logs/op-fw-access.log');
124+
$file = storage_path('logs/op-fw-access-' . $date . '.log');
119125
break;
120126
case 'error':
121-
$file = storage_path('logs/error.log');
127+
$file = storage_path('logs/error-' . $date . '.log');
122128
break;
123129
}
124130

0 commit comments

Comments
 (0)