Skip to content

Commit 782539e

Browse files
committed
merge conflict
2 parents 10028ab + e8faf67 commit 782539e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/DBTransactionRetryHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DBTransactionRetryHelper
2222
* @throws QueryException
2323
* @throws Throwable
2424
*/
25-
public static function transactionWithRetry(callable $callback, int $maxRetries = 5, int $retryDelay = 5, string $logFileName = 'mysql-deadlocks-log'): mixed
25+
public static function transactionWithRetry(callable $callback, int $maxRetries = 3, int $retryDelay = 2, string $logFileName = 'mysql-deadlocks'): mixed
2626
{
2727
$attempt = 0;
2828
$log = [];
@@ -113,6 +113,7 @@ protected static function buildLogContext(QueryException $e, int $attempt): arra
113113

114114
return array_merge([
115115
'attempt' => $attempt,
116+
'errorInfo' => $e->errorInfo,
116117
'ExceptionName' => get_class($e),
117118
'QueryException' => $e->getMessage(),
118119
'trace' => getDebugBacktraceArray() ?? null,

src/Helper.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@ function generateLog($var, $logFileName, $logType = 'error'): void
2424
$date = function_exists('now') ? now()->toDateString() : date('Y-m-d');
2525

2626
if (empty($logFileName)) {
27-
$logFilePath = storage_path('logs/general_' . $date . '.log');
27+
$logFilePath = storage_path('logs/' . date('Y-m-d') . 'general_' . $date . '.log');
2828
} else {
29-
$logFilePath = storage_path("logs/{$logFileName}_" . $date . '.log');
29+
$logFilePath = storage_path("logs/" . date('Y-m-d') . "{$logFileName}_" . $date . '.log');
3030
}
3131
$log = Log::build([
3232
'driver' => 'single',
3333
'path' => $logFilePath,
3434
]);
35-
$payload = is_array($var) ? $var : ['message' => (string) $var];
35+
$payload = is_array($var) ? $var : ['message' => (string)$var];
36+
$attempts = $var['attempt'] ?? 0;
37+
$errorInfo = $var['errorInfo'][2] ?? '';
38+
3639
if ($logType === 'error') {
37-
$log->error($payload);
40+
$log->error($attempts . ' ' . $errorInfo, $payload);
3841
} elseif ($logType === 'warning') {
39-
$log->warning($payload);
42+
$log->warning($attempts . ' ' . $errorInfo, $payload);
4043
} else {
41-
$log->info($payload);
44+
$log->info($attempts . ' ' . $errorInfo, $payload);
4245
}
4346
}
4447
}

0 commit comments

Comments
 (0)