forked from baron/baron-sso
userfront gateway 분리.
This commit is contained in:
@@ -469,6 +469,9 @@ class AuthProxyService {
|
||||
}
|
||||
|
||||
static Future<void> sendLog(String level, String message, {Map<String, dynamic>? data}) async {
|
||||
if (!_canSendClientLog()) {
|
||||
return;
|
||||
}
|
||||
final url = Uri.parse('$_baseUrl/api/v1/client-log');
|
||||
try {
|
||||
await http.post(
|
||||
@@ -480,7 +483,9 @@ class AuthProxyService {
|
||||
if (data != null) 'data': data,
|
||||
}),
|
||||
);
|
||||
_recordClientLogSuccess();
|
||||
} catch (_) {
|
||||
_recordClientLogFailure();
|
||||
// Ignore logging errors to prevent loops
|
||||
}
|
||||
}
|
||||
@@ -493,6 +498,34 @@ class AuthProxyService {
|
||||
await sendLog('ERROR', message, data: data);
|
||||
}
|
||||
|
||||
static int _clientLogFailureCount = 0;
|
||||
static DateTime? _clientLogLastFailureAt;
|
||||
static DateTime? _clientLogOpenUntil;
|
||||
|
||||
static bool _canSendClientLog() {
|
||||
final now = DateTime.now();
|
||||
final openUntil = _clientLogOpenUntil;
|
||||
if (openUntil != null && now.isBefore(openUntil)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _recordClientLogFailure() {
|
||||
_clientLogFailureCount += 1;
|
||||
_clientLogLastFailureAt = DateTime.now();
|
||||
if (_clientLogFailureCount >= 3) {
|
||||
_clientLogOpenUntil = DateTime.now().add(const Duration(minutes: 1));
|
||||
_clientLogFailureCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void _recordClientLogSuccess() {
|
||||
_clientLogFailureCount = 0;
|
||||
_clientLogLastFailureAt = null;
|
||||
_clientLogOpenUntil = null;
|
||||
}
|
||||
|
||||
// --- Signup Methods ---
|
||||
|
||||
static Future<bool> checkEmailAvailability(String email) async {
|
||||
|
||||
@@ -25,7 +25,7 @@ class LoggerService {
|
||||
);
|
||||
|
||||
// 2. Configure Standard Logger (logging package)
|
||||
std_log.Logger.root.level = kReleaseMode ? std_log.Level.INFO : std_log.Level.ALL;
|
||||
std_log.Logger.root.level = kReleaseMode ? std_log.Level.WARNING : std_log.Level.ALL;
|
||||
|
||||
std_log.Logger.root.onRecord.listen((record) {
|
||||
if (kReleaseMode) {
|
||||
@@ -71,7 +71,7 @@ class LoggerService {
|
||||
debugPrint(jsonEncode(logData));
|
||||
|
||||
// 2. Relay to Backend (Docker Terminal)
|
||||
if (record.level >= std_log.Level.INFO) {
|
||||
if (record.level >= std_log.Level.WARNING) {
|
||||
AuthProxyService.sendLog(
|
||||
record.level.name,
|
||||
record.message,
|
||||
|
||||
Reference in New Issue
Block a user