query("SHOW TABLES LIKE 'activity_log'")->getNumRows() === 0) { return; } $mbIdx = session()->get('mb_idx'); $ip = service('request')->getIPAddress(); model(\App\Models\ActivityLogModel::class)->insert([ 'al_mb_idx' => $mbIdx ? (int) $mbIdx : null, 'al_action' => $action, 'al_table' => $table, 'al_record_id' => $recordId, 'al_data_before' => $before !== null ? json_encode($before, JSON_UNESCAPED_UNICODE) : null, 'al_data_after' => $after !== null ? json_encode($after, JSON_UNESCAPED_UNICODE) : null, 'al_ip' => $ip, 'al_regdate' => date('Y-m-d H:i:s'), ]); } catch (\Throwable $e) { // 로깅 실패 시 본 로직 방해하지 않음 log_message('error', 'audit_log failed: ' . $e->getMessage()); } } }