unrealon 1.0.9__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unrealon/__init__.py +23 -21
- unrealon-1.1.1.dist-info/METADATA +722 -0
- unrealon-1.1.1.dist-info/RECORD +82 -0
- {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info}/WHEEL +1 -1
- unrealon-1.1.1.dist-info/entry_points.txt +9 -0
- {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info/licenses}/LICENSE +1 -1
- unrealon_bridge/__init__.py +114 -0
- unrealon_bridge/cli.py +316 -0
- unrealon_bridge/client/__init__.py +93 -0
- unrealon_bridge/client/base.py +78 -0
- unrealon_bridge/client/commands.py +89 -0
- unrealon_bridge/client/connection.py +90 -0
- unrealon_bridge/client/events.py +65 -0
- unrealon_bridge/client/health.py +38 -0
- unrealon_bridge/client/html_parser.py +146 -0
- unrealon_bridge/client/logging.py +139 -0
- unrealon_bridge/client/proxy.py +70 -0
- unrealon_bridge/client/scheduler.py +450 -0
- unrealon_bridge/client/session.py +70 -0
- unrealon_bridge/configs/__init__.py +14 -0
- unrealon_bridge/configs/bridge_config.py +212 -0
- unrealon_bridge/configs/bridge_config.yaml +39 -0
- unrealon_bridge/models/__init__.py +138 -0
- unrealon_bridge/models/base.py +28 -0
- unrealon_bridge/models/command.py +41 -0
- unrealon_bridge/models/events.py +40 -0
- unrealon_bridge/models/html_parser.py +79 -0
- unrealon_bridge/models/logging.py +55 -0
- unrealon_bridge/models/parser.py +63 -0
- unrealon_bridge/models/proxy.py +41 -0
- unrealon_bridge/models/requests.py +95 -0
- unrealon_bridge/models/responses.py +88 -0
- unrealon_bridge/models/scheduler.py +592 -0
- unrealon_bridge/models/session.py +28 -0
- unrealon_bridge/server/__init__.py +91 -0
- unrealon_bridge/server/base.py +171 -0
- unrealon_bridge/server/handlers/__init__.py +23 -0
- unrealon_bridge/server/handlers/command.py +110 -0
- unrealon_bridge/server/handlers/html_parser.py +139 -0
- unrealon_bridge/server/handlers/logging.py +95 -0
- unrealon_bridge/server/handlers/parser.py +95 -0
- unrealon_bridge/server/handlers/proxy.py +75 -0
- unrealon_bridge/server/handlers/scheduler.py +545 -0
- unrealon_bridge/server/handlers/session.py +66 -0
- unrealon_browser/__init__.py +61 -18
- unrealon_browser/{src/cli → cli}/browser_cli.py +6 -13
- unrealon_browser/{src/cli → cli}/cookies_cli.py +5 -1
- unrealon_browser/{src/core → core}/browser_manager.py +2 -2
- unrealon_browser/{src/managers → managers}/captcha.py +1 -1
- unrealon_browser/{src/managers → managers}/cookies.py +1 -1
- unrealon_browser/managers/logger_bridge.py +231 -0
- unrealon_browser/{src/managers → managers}/profile.py +1 -1
- unrealon_driver/__init__.py +73 -19
- unrealon_driver/browser/__init__.py +8 -0
- unrealon_driver/browser/config.py +74 -0
- unrealon_driver/browser/manager.py +416 -0
- unrealon_driver/exceptions.py +28 -0
- unrealon_driver/parser/__init__.py +55 -0
- unrealon_driver/parser/cli_manager.py +141 -0
- unrealon_driver/parser/daemon_manager.py +227 -0
- unrealon_driver/parser/managers/__init__.py +46 -0
- unrealon_driver/parser/managers/browser.py +51 -0
- unrealon_driver/parser/managers/config.py +281 -0
- unrealon_driver/parser/managers/error.py +412 -0
- unrealon_driver/parser/managers/html.py +732 -0
- unrealon_driver/parser/managers/logging.py +609 -0
- unrealon_driver/parser/managers/result.py +321 -0
- unrealon_driver/parser/parser_manager.py +628 -0
- unrealon/sdk_config.py +0 -88
- unrealon-1.0.9.dist-info/METADATA +0 -810
- unrealon-1.0.9.dist-info/RECORD +0 -246
- unrealon_browser/pyproject.toml +0 -182
- unrealon_browser/src/__init__.py +0 -62
- unrealon_browser/src/managers/logger_bridge.py +0 -395
- unrealon_driver/README.md +0 -204
- unrealon_driver/pyproject.toml +0 -187
- unrealon_driver/src/__init__.py +0 -90
- unrealon_driver/src/cli/__init__.py +0 -10
- unrealon_driver/src/cli/main.py +0 -66
- unrealon_driver/src/cli/simple.py +0 -510
- unrealon_driver/src/config/__init__.py +0 -11
- unrealon_driver/src/config/auto_config.py +0 -478
- unrealon_driver/src/core/__init__.py +0 -18
- unrealon_driver/src/core/exceptions.py +0 -289
- unrealon_driver/src/core/parser.py +0 -638
- unrealon_driver/src/dto/__init__.py +0 -66
- unrealon_driver/src/dto/cli.py +0 -119
- unrealon_driver/src/dto/config.py +0 -18
- unrealon_driver/src/dto/events.py +0 -237
- unrealon_driver/src/dto/execution.py +0 -313
- unrealon_driver/src/dto/services.py +0 -311
- unrealon_driver/src/execution/__init__.py +0 -23
- unrealon_driver/src/execution/daemon_mode.py +0 -317
- unrealon_driver/src/execution/interactive_mode.py +0 -88
- unrealon_driver/src/execution/modes.py +0 -45
- unrealon_driver/src/execution/scheduled_mode.py +0 -209
- unrealon_driver/src/execution/test_mode.py +0 -250
- unrealon_driver/src/logging/__init__.py +0 -24
- unrealon_driver/src/logging/driver_logger.py +0 -512
- unrealon_driver/src/services/__init__.py +0 -24
- unrealon_driver/src/services/browser_service.py +0 -726
- unrealon_driver/src/services/llm/__init__.py +0 -15
- unrealon_driver/src/services/llm/browser_llm_service.py +0 -363
- unrealon_driver/src/services/llm/llm.py +0 -195
- unrealon_driver/src/services/logger_service.py +0 -232
- unrealon_driver/src/services/metrics_service.py +0 -185
- unrealon_driver/src/services/scheduler_service.py +0 -489
- unrealon_driver/src/services/websocket_service.py +0 -362
- unrealon_driver/src/utils/__init__.py +0 -16
- unrealon_driver/src/utils/service_factory.py +0 -317
- unrealon_driver/src/utils/time_formatter.py +0 -338
- unrealon_llm/README.md +0 -44
- unrealon_llm/__init__.py +0 -26
- unrealon_llm/pyproject.toml +0 -154
- unrealon_llm/src/__init__.py +0 -228
- unrealon_llm/src/cli/__init__.py +0 -0
- unrealon_llm/src/core/__init__.py +0 -11
- unrealon_llm/src/core/smart_client.py +0 -438
- unrealon_llm/src/dto/__init__.py +0 -155
- unrealon_llm/src/dto/models/__init__.py +0 -0
- unrealon_llm/src/dto/models/config.py +0 -343
- unrealon_llm/src/dto/models/core.py +0 -328
- unrealon_llm/src/dto/models/enums.py +0 -123
- unrealon_llm/src/dto/models/html_analysis.py +0 -345
- unrealon_llm/src/dto/models/statistics.py +0 -473
- unrealon_llm/src/dto/models/translation.py +0 -383
- unrealon_llm/src/dto/models/type_conversion.py +0 -462
- unrealon_llm/src/dto/schemas/__init__.py +0 -0
- unrealon_llm/src/exceptions.py +0 -392
- unrealon_llm/src/llm_config/__init__.py +0 -20
- unrealon_llm/src/llm_config/logging_config.py +0 -178
- unrealon_llm/src/llm_logging/__init__.py +0 -42
- unrealon_llm/src/llm_logging/llm_events.py +0 -107
- unrealon_llm/src/llm_logging/llm_logger.py +0 -466
- unrealon_llm/src/managers/__init__.py +0 -15
- unrealon_llm/src/managers/cache_manager.py +0 -67
- unrealon_llm/src/managers/cost_manager.py +0 -107
- unrealon_llm/src/managers/request_manager.py +0 -298
- unrealon_llm/src/modules/__init__.py +0 -0
- unrealon_llm/src/modules/html_processor/__init__.py +0 -25
- unrealon_llm/src/modules/html_processor/base_processor.py +0 -415
- unrealon_llm/src/modules/html_processor/details_processor.py +0 -85
- unrealon_llm/src/modules/html_processor/listing_processor.py +0 -91
- unrealon_llm/src/modules/html_processor/models/__init__.py +0 -20
- unrealon_llm/src/modules/html_processor/models/processing_models.py +0 -40
- unrealon_llm/src/modules/html_processor/models/universal_model.py +0 -56
- unrealon_llm/src/modules/html_processor/processor.py +0 -102
- unrealon_llm/src/modules/llm/__init__.py +0 -0
- unrealon_llm/src/modules/translator/__init__.py +0 -0
- unrealon_llm/src/provider.py +0 -116
- unrealon_llm/src/utils/__init__.py +0 -95
- unrealon_llm/src/utils/common.py +0 -64
- unrealon_llm/src/utils/data_extractor.py +0 -188
- unrealon_llm/src/utils/html_cleaner.py +0 -767
- unrealon_llm/src/utils/language_detector.py +0 -308
- unrealon_llm/src/utils/models_cache.py +0 -592
- unrealon_llm/src/utils/smart_counter.py +0 -229
- unrealon_llm/src/utils/token_counter.py +0 -189
- unrealon_sdk/README.md +0 -25
- unrealon_sdk/__init__.py +0 -30
- unrealon_sdk/pyproject.toml +0 -231
- unrealon_sdk/src/__init__.py +0 -150
- unrealon_sdk/src/cli/__init__.py +0 -12
- unrealon_sdk/src/cli/commands/__init__.py +0 -22
- unrealon_sdk/src/cli/commands/benchmark.py +0 -42
- unrealon_sdk/src/cli/commands/diagnostics.py +0 -573
- unrealon_sdk/src/cli/commands/health.py +0 -46
- unrealon_sdk/src/cli/commands/integration.py +0 -498
- unrealon_sdk/src/cli/commands/reports.py +0 -43
- unrealon_sdk/src/cli/commands/security.py +0 -36
- unrealon_sdk/src/cli/commands/server.py +0 -483
- unrealon_sdk/src/cli/commands/servers.py +0 -56
- unrealon_sdk/src/cli/commands/tests.py +0 -55
- unrealon_sdk/src/cli/main.py +0 -126
- unrealon_sdk/src/cli/utils/reporter.py +0 -519
- unrealon_sdk/src/clients/openapi.yaml +0 -3347
- unrealon_sdk/src/clients/python_http/__init__.py +0 -3
- unrealon_sdk/src/clients/python_http/api_config.py +0 -228
- unrealon_sdk/src/clients/python_http/models/BaseModel.py +0 -12
- unrealon_sdk/src/clients/python_http/models/BroadcastDeliveryStats.py +0 -33
- unrealon_sdk/src/clients/python_http/models/BroadcastMessage.py +0 -17
- unrealon_sdk/src/clients/python_http/models/BroadcastMessageRequest.py +0 -35
- unrealon_sdk/src/clients/python_http/models/BroadcastPriority.py +0 -10
- unrealon_sdk/src/clients/python_http/models/BroadcastResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/BroadcastResultResponse.py +0 -33
- unrealon_sdk/src/clients/python_http/models/BroadcastTarget.py +0 -11
- unrealon_sdk/src/clients/python_http/models/ConnectionStats.py +0 -27
- unrealon_sdk/src/clients/python_http/models/ConnectionsResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/DeveloperMessageResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ErrorResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/HTTPValidationError.py +0 -16
- unrealon_sdk/src/clients/python_http/models/HealthResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/HealthStatus.py +0 -33
- unrealon_sdk/src/clients/python_http/models/LogLevel.py +0 -10
- unrealon_sdk/src/clients/python_http/models/LoggingRequest.py +0 -27
- unrealon_sdk/src/clients/python_http/models/LoggingResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/MaintenanceMode.py +0 -9
- unrealon_sdk/src/clients/python_http/models/MaintenanceModeRequest.py +0 -33
- unrealon_sdk/src/clients/python_http/models/MaintenanceStatusResponse.py +0 -39
- unrealon_sdk/src/clients/python_http/models/ParserCommandRequest.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ParserMessageResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/ParserRegistrationRequest.py +0 -28
- unrealon_sdk/src/clients/python_http/models/ParserRegistrationResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ParserType.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyBlockRequest.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyEndpointResponse.py +0 -20
- unrealon_sdk/src/clients/python_http/models/ProxyListResponse.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyProvider.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyPurchaseRequest.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ProxyResponse.py +0 -47
- unrealon_sdk/src/clients/python_http/models/ProxyRotationRequest.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ProxyStatus.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyUsageRequest.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyUsageStatsResponse.py +0 -26
- unrealon_sdk/src/clients/python_http/models/ServiceRegistrationDto.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ServiceStatsResponse.py +0 -31
- unrealon_sdk/src/clients/python_http/models/SessionStartRequest.py +0 -23
- unrealon_sdk/src/clients/python_http/models/SuccessResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/SystemNotificationResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ValidationError.py +0 -18
- unrealon_sdk/src/clients/python_http/models/ValidationErrorResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/WebSocketMetrics.py +0 -21
- unrealon_sdk/src/clients/python_http/models/__init__.py +0 -44
- unrealon_sdk/src/clients/python_http/services/None_service.py +0 -35
- unrealon_sdk/src/clients/python_http/services/ParserManagement_service.py +0 -190
- unrealon_sdk/src/clients/python_http/services/ProxyManagement_service.py +0 -289
- unrealon_sdk/src/clients/python_http/services/SocketLogging_service.py +0 -187
- unrealon_sdk/src/clients/python_http/services/SystemHealth_service.py +0 -119
- unrealon_sdk/src/clients/python_http/services/WebSocketAPI_service.py +0 -198
- unrealon_sdk/src/clients/python_http/services/__init__.py +0 -0
- unrealon_sdk/src/clients/python_http/services/admin_service.py +0 -125
- unrealon_sdk/src/clients/python_http/services/async_None_service.py +0 -35
- unrealon_sdk/src/clients/python_http/services/async_ParserManagement_service.py +0 -190
- unrealon_sdk/src/clients/python_http/services/async_ProxyManagement_service.py +0 -289
- unrealon_sdk/src/clients/python_http/services/async_SocketLogging_service.py +0 -189
- unrealon_sdk/src/clients/python_http/services/async_SystemHealth_service.py +0 -123
- unrealon_sdk/src/clients/python_http/services/async_WebSocketAPI_service.py +0 -200
- unrealon_sdk/src/clients/python_http/services/async_admin_service.py +0 -125
- unrealon_sdk/src/clients/python_websocket/__init__.py +0 -28
- unrealon_sdk/src/clients/python_websocket/client.py +0 -490
- unrealon_sdk/src/clients/python_websocket/events.py +0 -732
- unrealon_sdk/src/clients/python_websocket/example.py +0 -136
- unrealon_sdk/src/clients/python_websocket/types.py +0 -871
- unrealon_sdk/src/core/__init__.py +0 -64
- unrealon_sdk/src/core/client.py +0 -556
- unrealon_sdk/src/core/config.py +0 -465
- unrealon_sdk/src/core/exceptions.py +0 -239
- unrealon_sdk/src/core/metadata.py +0 -191
- unrealon_sdk/src/core/models.py +0 -142
- unrealon_sdk/src/core/types.py +0 -68
- unrealon_sdk/src/dto/__init__.py +0 -268
- unrealon_sdk/src/dto/authentication.py +0 -108
- unrealon_sdk/src/dto/cache.py +0 -208
- unrealon_sdk/src/dto/common.py +0 -19
- unrealon_sdk/src/dto/concurrency.py +0 -393
- unrealon_sdk/src/dto/events.py +0 -108
- unrealon_sdk/src/dto/health.py +0 -339
- unrealon_sdk/src/dto/load_balancing.py +0 -336
- unrealon_sdk/src/dto/logging.py +0 -230
- unrealon_sdk/src/dto/performance.py +0 -165
- unrealon_sdk/src/dto/rate_limiting.py +0 -295
- unrealon_sdk/src/dto/resource_pooling.py +0 -128
- unrealon_sdk/src/dto/structured_logging.py +0 -112
- unrealon_sdk/src/dto/task_scheduling.py +0 -121
- unrealon_sdk/src/dto/websocket.py +0 -55
- unrealon_sdk/src/enterprise/__init__.py +0 -59
- unrealon_sdk/src/enterprise/authentication.py +0 -401
- unrealon_sdk/src/enterprise/cache_manager.py +0 -578
- unrealon_sdk/src/enterprise/error_recovery.py +0 -494
- unrealon_sdk/src/enterprise/event_system.py +0 -549
- unrealon_sdk/src/enterprise/health_monitor.py +0 -747
- unrealon_sdk/src/enterprise/load_balancer.py +0 -964
- unrealon_sdk/src/enterprise/logging/__init__.py +0 -68
- unrealon_sdk/src/enterprise/logging/cleanup.py +0 -156
- unrealon_sdk/src/enterprise/logging/development.py +0 -744
- unrealon_sdk/src/enterprise/logging/service.py +0 -410
- unrealon_sdk/src/enterprise/multithreading_manager.py +0 -853
- unrealon_sdk/src/enterprise/performance_monitor.py +0 -539
- unrealon_sdk/src/enterprise/proxy_manager.py +0 -696
- unrealon_sdk/src/enterprise/rate_limiter.py +0 -652
- unrealon_sdk/src/enterprise/resource_pool.py +0 -763
- unrealon_sdk/src/enterprise/task_scheduler.py +0 -709
- unrealon_sdk/src/internal/__init__.py +0 -10
- unrealon_sdk/src/internal/command_router.py +0 -497
- unrealon_sdk/src/internal/connection_manager.py +0 -397
- unrealon_sdk/src/internal/http_client.py +0 -446
- unrealon_sdk/src/internal/websocket_client.py +0 -420
- unrealon_sdk/src/provider.py +0 -471
- unrealon_sdk/src/utils.py +0 -234
- /unrealon_browser/{src/cli → cli}/__init__.py +0 -0
- /unrealon_browser/{src/cli → cli}/interactive_mode.py +0 -0
- /unrealon_browser/{src/cli → cli}/main.py +0 -0
- /unrealon_browser/{src/core → core}/__init__.py +0 -0
- /unrealon_browser/{src/dto → dto}/__init__.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/config.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/core.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/dataclasses.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/detection.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/enums.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/statistics.py +0 -0
- /unrealon_browser/{src/managers → managers}/__init__.py +0 -0
- /unrealon_browser/{src/managers → managers}/stealth.py +0 -0
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
LoggingService - Structured Real-time Logging for Enterprise Parsing
|
|
3
|
-
|
|
4
|
-
Layer 3: Infrastructure Services - Enterprise logging with:
|
|
5
|
-
- Real-time log streaming via WebSocket
|
|
6
|
-
- Structured metadata with Pydantic v2 models
|
|
7
|
-
- Automatic buffering and batch processing
|
|
8
|
-
- Multiple destination support (local, WebSocket, external)
|
|
9
|
-
- Type-safe operations and correlation tracking
|
|
10
|
-
|
|
11
|
-
Enterprise Features:
|
|
12
|
-
- WebSocket-based real-time log streaming
|
|
13
|
-
- Structured metadata with full type safety
|
|
14
|
-
- Automatic buffering for performance
|
|
15
|
-
- Correlation tracking across requests
|
|
16
|
-
- Integration with external logging systems
|
|
17
|
-
- Performance metrics and log analytics
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
import asyncio
|
|
21
|
-
import logging
|
|
22
|
-
import json
|
|
23
|
-
from datetime import datetime, timezone
|
|
24
|
-
from typing import List, Optional, Any, Union, Callable, Dict
|
|
25
|
-
from dataclasses import dataclass, field
|
|
26
|
-
from enum import Enum
|
|
27
|
-
import uuid
|
|
28
|
-
from collections import deque
|
|
29
|
-
import threading
|
|
30
|
-
|
|
31
|
-
# Pydantic v2 for all data models
|
|
32
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
33
|
-
|
|
34
|
-
# Auto-generated models - use LogLevel from HTTP models (standard enum)
|
|
35
|
-
from unrealon_sdk.src.clients.python_http.models import LogLevel, LoggingRequest
|
|
36
|
-
|
|
37
|
-
# Auto-generated WebSocket models - main models for logging
|
|
38
|
-
from unrealon_sdk.src.clients.python_websocket.types import LogEntryMessage
|
|
39
|
-
|
|
40
|
-
# Core SDK components
|
|
41
|
-
from unrealon_sdk.src.core.config import AdapterConfig, LoggingConfig
|
|
42
|
-
from unrealon_sdk.src.core.exceptions import LoggingError
|
|
43
|
-
from unrealon_sdk.src.utils import generate_correlation_id
|
|
44
|
-
|
|
45
|
-
# DTO models for structured logging
|
|
46
|
-
from unrealon_sdk.src.dto.logging import LogDestination
|
|
47
|
-
from unrealon_sdk.src.dto.structured_logging import LogBuffer
|
|
48
|
-
|
|
49
|
-
# Development logging (avoid circular import)
|
|
50
|
-
from typing import TYPE_CHECKING
|
|
51
|
-
|
|
52
|
-
if TYPE_CHECKING:
|
|
53
|
-
from .development_logger import DevelopmentLogger
|
|
54
|
-
|
|
55
|
-
# SDK metadata models
|
|
56
|
-
from unrealon_sdk.src.core.metadata import LoggingServiceStatistics
|
|
57
|
-
|
|
58
|
-
logger = logging.getLogger(__name__)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# Use auto-generated LogEntryMessage directly for WebSocket logging
|
|
62
|
-
# All structured data goes into the entry field using flexible types
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class StructuredLogger:
|
|
66
|
-
"""
|
|
67
|
-
Type-safe structured logger using auto-generated LogEntryMessage.
|
|
68
|
-
|
|
69
|
-
Provides a familiar logging interface while ensuring all
|
|
70
|
-
log entries use the official WebSocket message format.
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
def __init__(self, name: str, service: "LoggingService"):
|
|
74
|
-
self.name = name
|
|
75
|
-
self.service = service
|
|
76
|
-
self._default_context: Dict[str, Any] = {}
|
|
77
|
-
|
|
78
|
-
def with_context(self, **context: Any) -> "StructuredLogger":
|
|
79
|
-
"""Create logger with additional context metadata."""
|
|
80
|
-
new_logger = StructuredLogger(self.name, self.service)
|
|
81
|
-
new_logger._default_context = {**self._default_context, **context}
|
|
82
|
-
return new_logger
|
|
83
|
-
|
|
84
|
-
def debug(self, message: str, **context: Any) -> None:
|
|
85
|
-
"""Log debug message with structured context."""
|
|
86
|
-
self._log(LogLevel.DEBUG, message, **context)
|
|
87
|
-
|
|
88
|
-
def info(self, message: str, **context: Any) -> None:
|
|
89
|
-
"""Log info message with structured context."""
|
|
90
|
-
self._log(LogLevel.INFO, message, **context)
|
|
91
|
-
|
|
92
|
-
def warning(self, message: str, **context: Any) -> None:
|
|
93
|
-
"""Log warning message with structured context."""
|
|
94
|
-
self._log(LogLevel.WARNING, message, **context)
|
|
95
|
-
|
|
96
|
-
def error(self, message: str, **context: Any) -> None:
|
|
97
|
-
"""Log error message with structured context."""
|
|
98
|
-
self._log(LogLevel.ERROR, message, **context)
|
|
99
|
-
|
|
100
|
-
def critical(self, message: str, **context: Any) -> None:
|
|
101
|
-
"""Log critical message with structured context."""
|
|
102
|
-
self._log(LogLevel.CRITICAL, message, **context)
|
|
103
|
-
|
|
104
|
-
def _log(self, level: LogLevel, message: str, **context: Any) -> None:
|
|
105
|
-
"""Internal logging method using auto-generated LogEntryMessage."""
|
|
106
|
-
now = datetime.now(timezone.utc)
|
|
107
|
-
|
|
108
|
-
# Combine default context with provided context
|
|
109
|
-
combined_context = {
|
|
110
|
-
**self._default_context,
|
|
111
|
-
**context,
|
|
112
|
-
# Add runtime info
|
|
113
|
-
"logger_name": self.name,
|
|
114
|
-
"thread_id": str(threading.get_ident()),
|
|
115
|
-
"level": level.value,
|
|
116
|
-
"correlation_id": generate_correlation_id(),
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
# Create LogEntryMessage using the auto-generated model
|
|
120
|
-
entry = LogEntryMessage(
|
|
121
|
-
type="log_entry",
|
|
122
|
-
session_id=self.service._session_id,
|
|
123
|
-
entry=combined_context, # All structured data goes here
|
|
124
|
-
timestamp=now.isoformat(),
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
# Add the actual log message to entry data
|
|
128
|
-
entry.entry["message"] = message
|
|
129
|
-
entry.entry["timestamp"] = now.isoformat()
|
|
130
|
-
|
|
131
|
-
self.service.log_entry(entry)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
class LoggingService:
|
|
135
|
-
"""
|
|
136
|
-
Enterprise-grade structured logging service.
|
|
137
|
-
|
|
138
|
-
Features:
|
|
139
|
-
- Real-time WebSocket log streaming
|
|
140
|
-
- Structured metadata with type safety
|
|
141
|
-
- Automatic buffering and batching
|
|
142
|
-
- Multiple destination support
|
|
143
|
-
- Correlation tracking
|
|
144
|
-
- Performance monitoring
|
|
145
|
-
"""
|
|
146
|
-
|
|
147
|
-
def __init__(self, config: AdapterConfig):
|
|
148
|
-
"""
|
|
149
|
-
Initialize LoggingService with configuration.
|
|
150
|
-
|
|
151
|
-
Args:
|
|
152
|
-
config: Adapter configuration containing logging settings
|
|
153
|
-
"""
|
|
154
|
-
self.config = config
|
|
155
|
-
self.logging_config = config.logging_config or LoggingConfig()
|
|
156
|
-
self.logger = logger
|
|
157
|
-
|
|
158
|
-
# Session management for WebSocket logging
|
|
159
|
-
self._session_id = generate_correlation_id()
|
|
160
|
-
|
|
161
|
-
# WebSocket client for real-time streaming (will be injected)
|
|
162
|
-
self._websocket_client = None
|
|
163
|
-
|
|
164
|
-
# Buffering for performance
|
|
165
|
-
self._buffer = LogBuffer(
|
|
166
|
-
max_size=self.logging_config.buffer_size,
|
|
167
|
-
flush_interval_seconds=self.logging_config.flush_interval_seconds,
|
|
168
|
-
)
|
|
169
|
-
self._buffer.flush_callback = self._flush_entries
|
|
170
|
-
|
|
171
|
-
# Structured loggers registry
|
|
172
|
-
self._loggers: Dict[str, StructuredLogger] = {}
|
|
173
|
-
|
|
174
|
-
# Statistics
|
|
175
|
-
self._total_logs = 0
|
|
176
|
-
self._logs_by_level = {level: 0 for level in LogLevel}
|
|
177
|
-
self._websocket_errors = 0
|
|
178
|
-
|
|
179
|
-
# Background tasks
|
|
180
|
-
self._initialized = False
|
|
181
|
-
|
|
182
|
-
current_level = self.logging_config.level or self.logging_config.log_level
|
|
183
|
-
self.logger.info(f"LoggingService initialized with level: {current_level}")
|
|
184
|
-
|
|
185
|
-
async def initialize(self, websocket_client: Any) -> None:
|
|
186
|
-
"""Initialize logging service with WebSocket client."""
|
|
187
|
-
self._websocket_client = websocket_client
|
|
188
|
-
|
|
189
|
-
if self.logging_config.enabled:
|
|
190
|
-
await self._buffer.start_auto_flush()
|
|
191
|
-
|
|
192
|
-
self._initialized = True
|
|
193
|
-
self.logger.info("LoggingService initialization complete")
|
|
194
|
-
|
|
195
|
-
async def shutdown(self) -> None:
|
|
196
|
-
"""Shutdown logging service and flush remaining logs."""
|
|
197
|
-
await self._buffer.stop_auto_flush()
|
|
198
|
-
self._initialized = False
|
|
199
|
-
self.logger.info("LoggingService shutdown complete")
|
|
200
|
-
|
|
201
|
-
def get_logger(self, name: str) -> StructuredLogger:
|
|
202
|
-
"""
|
|
203
|
-
Get or create a structured logger.
|
|
204
|
-
|
|
205
|
-
Args:
|
|
206
|
-
name: Logger name
|
|
207
|
-
|
|
208
|
-
Returns:
|
|
209
|
-
StructuredLogger instance
|
|
210
|
-
"""
|
|
211
|
-
if name not in self._loggers:
|
|
212
|
-
self._loggers[name] = StructuredLogger(name, self)
|
|
213
|
-
|
|
214
|
-
return self._loggers[name]
|
|
215
|
-
|
|
216
|
-
def log_entry(self, entry: LogEntryMessage) -> None:
|
|
217
|
-
"""
|
|
218
|
-
Log a structured entry using auto-generated LogEntryMessage.
|
|
219
|
-
|
|
220
|
-
Args:
|
|
221
|
-
entry: LogEntryMessage to process
|
|
222
|
-
"""
|
|
223
|
-
if not self.logging_config.enabled:
|
|
224
|
-
return
|
|
225
|
-
|
|
226
|
-
# Extract log level from entry data for filtering
|
|
227
|
-
log_level_str = entry.entry.get("level", "info")
|
|
228
|
-
try:
|
|
229
|
-
entry_level = LogLevel(log_level_str)
|
|
230
|
-
except ValueError:
|
|
231
|
-
entry_level = LogLevel.INFO # Default fallback
|
|
232
|
-
|
|
233
|
-
# Check log level filtering
|
|
234
|
-
current_level = self.logging_config.level or self.logging_config.log_level
|
|
235
|
-
current_level_value = self._get_level_value(current_level)
|
|
236
|
-
entry_level_value = self._get_level_value(entry_level)
|
|
237
|
-
|
|
238
|
-
if entry_level_value < current_level_value:
|
|
239
|
-
return # Skip logs below configured level
|
|
240
|
-
|
|
241
|
-
# Update statistics
|
|
242
|
-
self._total_logs += 1
|
|
243
|
-
self._logs_by_level[entry_level] += 1
|
|
244
|
-
|
|
245
|
-
# Add to buffer for processing
|
|
246
|
-
self._buffer.add_entry(entry)
|
|
247
|
-
|
|
248
|
-
# Also send to console if configured
|
|
249
|
-
if LogDestination.CONSOLE in self.logging_config.destinations:
|
|
250
|
-
self._log_to_console(entry)
|
|
251
|
-
|
|
252
|
-
def _get_level_value(self, level: LogLevel) -> int:
|
|
253
|
-
"""Get numeric value for log level comparison."""
|
|
254
|
-
level_values = {
|
|
255
|
-
LogLevel.DEBUG: 10,
|
|
256
|
-
LogLevel.INFO: 20,
|
|
257
|
-
LogLevel.WARNING: 30,
|
|
258
|
-
LogLevel.ERROR: 40,
|
|
259
|
-
LogLevel.CRITICAL: 50,
|
|
260
|
-
}
|
|
261
|
-
return level_values.get(level, 0)
|
|
262
|
-
|
|
263
|
-
def _log_to_console(self, entry: LogEntryMessage) -> None:
|
|
264
|
-
"""Log entry to console using standard logging."""
|
|
265
|
-
# Extract log level from entry data
|
|
266
|
-
level_str = entry.entry.get("level", "info")
|
|
267
|
-
try:
|
|
268
|
-
log_level = LogLevel(level_str)
|
|
269
|
-
except ValueError:
|
|
270
|
-
log_level = LogLevel.INFO
|
|
271
|
-
|
|
272
|
-
python_level = {
|
|
273
|
-
LogLevel.DEBUG: logging.DEBUG,
|
|
274
|
-
LogLevel.INFO: logging.INFO,
|
|
275
|
-
LogLevel.WARNING: logging.WARNING,
|
|
276
|
-
LogLevel.ERROR: logging.ERROR,
|
|
277
|
-
LogLevel.CRITICAL: logging.CRITICAL,
|
|
278
|
-
}.get(log_level, logging.INFO)
|
|
279
|
-
|
|
280
|
-
# Extract message and metadata from entry
|
|
281
|
-
message = entry.entry.get("message", "")
|
|
282
|
-
correlation_id = entry.entry.get("correlation_id", "")
|
|
283
|
-
parser_id = entry.entry.get("parser_id", "")
|
|
284
|
-
|
|
285
|
-
# Format message with key metadata
|
|
286
|
-
metadata_str = ""
|
|
287
|
-
if correlation_id:
|
|
288
|
-
metadata_str += f" [corr_id={correlation_id[:8]}]"
|
|
289
|
-
if parser_id:
|
|
290
|
-
metadata_str += f" [parser={parser_id}]"
|
|
291
|
-
|
|
292
|
-
formatted_message = f"{message}{metadata_str}"
|
|
293
|
-
self.logger.log(python_level, formatted_message)
|
|
294
|
-
|
|
295
|
-
async def _flush_entries(self, entries: List[LogEntryMessage]) -> None:
|
|
296
|
-
"""Flush buffered entries to configured destinations."""
|
|
297
|
-
if not entries:
|
|
298
|
-
return
|
|
299
|
-
|
|
300
|
-
# Send to WebSocket if enabled and connected
|
|
301
|
-
if (
|
|
302
|
-
LogDestination.WEBSOCKET in self.logging_config.destinations
|
|
303
|
-
and self._websocket_client
|
|
304
|
-
and self._websocket_client.is_connected()
|
|
305
|
-
):
|
|
306
|
-
|
|
307
|
-
await self._send_to_websocket(entries)
|
|
308
|
-
|
|
309
|
-
# Send to other destinations (file, HTTP, etc.)
|
|
310
|
-
# Implementation would depend on configuration
|
|
311
|
-
|
|
312
|
-
async def _send_to_websocket(self, entries: List[LogEntryMessage]) -> None:
|
|
313
|
-
"""Send log entries to WebSocket with timeout to prevent blocking."""
|
|
314
|
-
try:
|
|
315
|
-
# Send entries concurrently with timeout
|
|
316
|
-
send_tasks = [
|
|
317
|
-
asyncio.create_task(self._websocket_client.send_log(entry))
|
|
318
|
-
for entry in entries
|
|
319
|
-
]
|
|
320
|
-
|
|
321
|
-
if send_tasks:
|
|
322
|
-
await asyncio.wait_for(
|
|
323
|
-
asyncio.gather(*send_tasks, return_exceptions=True),
|
|
324
|
-
timeout=3.0 # 3 second timeout for all sends
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
self.logger.debug(f"Sent {len(entries)} log entries via WebSocket")
|
|
328
|
-
|
|
329
|
-
except asyncio.TimeoutError:
|
|
330
|
-
self._websocket_errors += len(entries)
|
|
331
|
-
self.logger.warning(f"WebSocket send timeout - attempted {len(entries)} entries")
|
|
332
|
-
except Exception as e:
|
|
333
|
-
self._websocket_errors += 1
|
|
334
|
-
self.logger.error(f"Failed to send logs via WebSocket: {e}")
|
|
335
|
-
|
|
336
|
-
def get_statistics(self) -> LoggingServiceStatistics:
|
|
337
|
-
"""Get comprehensive logging statistics."""
|
|
338
|
-
return LoggingServiceStatistics(
|
|
339
|
-
total_logs=self._total_logs,
|
|
340
|
-
logs_by_level={level.value: count for level, count in self._logs_by_level.items()},
|
|
341
|
-
websocket_logs=self._total_logs - self._websocket_errors,
|
|
342
|
-
buffer_size=len(self._buffer.entries),
|
|
343
|
-
failed_sends=self._websocket_errors,
|
|
344
|
-
last_flush=getattr(self, "_last_flush", datetime.now(timezone.utc)),
|
|
345
|
-
)
|
|
346
|
-
|
|
347
|
-
async def test_connectivity(self) -> bool:
|
|
348
|
-
"""Test WebSocket connectivity for logging."""
|
|
349
|
-
if not self._websocket_client:
|
|
350
|
-
return False
|
|
351
|
-
|
|
352
|
-
try:
|
|
353
|
-
test_entry = LogEntryMessage(
|
|
354
|
-
type="log_entry",
|
|
355
|
-
session_id=self._session_id,
|
|
356
|
-
entry={
|
|
357
|
-
"level": LogLevel.DEBUG.value,
|
|
358
|
-
"message": "Connectivity test from LoggingService",
|
|
359
|
-
"correlation_id": generate_correlation_id(),
|
|
360
|
-
"test": True,
|
|
361
|
-
},
|
|
362
|
-
timestamp=datetime.now(timezone.utc).isoformat(),
|
|
363
|
-
)
|
|
364
|
-
|
|
365
|
-
await self._websocket_client.send_log(test_entry)
|
|
366
|
-
return True
|
|
367
|
-
|
|
368
|
-
except Exception as e:
|
|
369
|
-
self.logger.error(f"Logging connectivity test failed: {e}")
|
|
370
|
-
return False
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
# Convenience function for getting loggers
|
|
374
|
-
def get_logger(
|
|
375
|
-
name: str, service: Optional[LoggingService] = None
|
|
376
|
-
) -> Union[StructuredLogger, logging.Logger]:
|
|
377
|
-
"""
|
|
378
|
-
Get a structured logger if service is available, otherwise fallback to standard logger.
|
|
379
|
-
|
|
380
|
-
Automatically performs log cleanup on first call to ensure clean logging environment.
|
|
381
|
-
|
|
382
|
-
Args:
|
|
383
|
-
name: Logger name
|
|
384
|
-
service: LoggingService instance, optional
|
|
385
|
-
|
|
386
|
-
Returns:
|
|
387
|
-
StructuredLogger if service provided, otherwise standard Logger
|
|
388
|
-
"""
|
|
389
|
-
if service and service._initialized:
|
|
390
|
-
return service.get_logger(name)
|
|
391
|
-
else:
|
|
392
|
-
# Use standard logger - cleanup handled at module initialization
|
|
393
|
-
return logging.getLogger(name)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
# Centralized exports for easy importing
|
|
397
|
-
# Import all logging-related models from this module
|
|
398
|
-
__all__ = [
|
|
399
|
-
# Core service
|
|
400
|
-
"LoggingService",
|
|
401
|
-
"StructuredLogger",
|
|
402
|
-
"get_logger",
|
|
403
|
-
# Enums and types
|
|
404
|
-
"LogDestination",
|
|
405
|
-
"LogBuffer",
|
|
406
|
-
# Auto-generated models (re-exported for convenience)
|
|
407
|
-
"LogLevel",
|
|
408
|
-
"LoggingRequest",
|
|
409
|
-
"LogEntryMessage",
|
|
410
|
-
]
|