askrobots / dbbasic-object-primitive
Public
Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.
02_hello_with_logging.py · 609 bytes · 29 lines
| 1 | """ |
| 2 | 02_hello_with_logging.py - Object with self-logging |
| 3 | """ |
| 4 | |
| 5 | # The runtime will inject these |
| 6 | _logger = None |
| 7 | _state_manager = None |
| 8 | |
| 9 | |
| 10 | def GET(request): |
| 11 | """Return a greeting with logging""" |
| 12 | |
| 13 | # Extract user info from request |
| 14 | user_id = request.get('user_id', 'anonymous') |
| 15 | ip_address = request.get('ip_address', 'unknown') |
| 16 | |
| 17 | # Log the request |
| 18 | if _logger: |
| 19 | _logger.info( |
| 20 | 'Greeting requested', |
| 21 | user_id=user_id, |
| 22 | ip_address=ip_address, |
| 23 | ) |
| 24 | |
| 25 | # Return greeting |
| 26 | return { |
| 27 | 'status': 'ok', |
| 28 | 'message': f'Hello, {user_id}!', |
| 29 | } |