The before code mixes logging inside the main service, making it harder to maintain. The after code moves logging to a sidecar service running separately, which receives data via HTTP. This keeps the main service focused and allows independent updates to logging.
### Before: Auxiliary logic embedded in main service
class Service:
def process(self, data):
# Main logic
result = self._compute(data)
# Logging directly here
print(f"Processed data: {result}")
return result
### After: Auxiliary logic moved to sidecar
# Main service code
class Service:
def process(self, data):
result = self._compute(data)
# Send data to sidecar via HTTP
import requests
requests.post('http://localhost:9000/log', json={'result': result})
return result
# Sidecar code (runs separately)
from flask import Flask, request
app = Flask(__name__)
@app.route('/log', methods=['POST'])
def log():
data = request.json
print(f"Sidecar logging: {data['result']}")
return '', 204
if __name__ == '__main__':
app.run(port=9000)