-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use log/slog
for logging
#8
Conversation
@iBug Any thoughts? I didn’t know how Vlab infrastructure handles the log so I’m trying to keep it semantically identical based on JSON specifications. If possible we should eliminate such workarounds eventually. |
We have a ~30-line Python listener that receives these JSON-over-UDP packets and writes them to a MySQL database so that we have connection statistics when we need them. This is certainly room for improvement, such as writing them to a text file and let Python (or another log-to-DB program) follow it with You have the freedom of designing the new output method and format, as long as it's reasonably easy to parse and follow real-time. |
I just pushed a small patch 6b75357 that changed a few fields of Also, extra fields that def parse_log(msg_json):
remote_ip = msg_json['remote_ip']
host_ip = msg_json['host_ip']
client_type = msg_json['client_type']
authenticated = msg_json['authenticated']
username = msg_json['username']
if client_type == "SSH":
# Drop username as it's not student ID for SSH
username = ""
connect_timestamp = msg_json['connect_time']
disconnect_timestamp = msg_json['disconnect_time']
connect_time = datetime.datetime.fromtimestamp(connect_timestamp).strftime('%Y-%m-%d %H:%M:%S')
disconnect_time = datetime.datetime.fromtimestamp(disconnect_timestamp).strftime('%Y-%m-%d %H:%M:%S')
return (remote_ip, host_ip, client_type, authenticated, username, connect_time, disconnect_time) For the database column types, These are just for reference and I'll handle the Python part myself. |
Would you mind if we send the (dis)connection time in a String like this:
|
Delayed for the OpenTelemetry update… I would like to do a whole refresh, including changes to keys that should be absolutely breaking. |
See #8 (comment):
My recommendation is do whatever you find suitable for now. I'll review the new format before merging or deploying, and then discuss if there is any inconvenience for us. |
Get it. I would still tend to avoid breaking changes for a smooth upgrade experience. All these compatibility codes shall be safely removed when we reached a point (seemingly v0.1). This PR is ready in its current state. The logging part is of lower priority for me than authentication so further improvements shall be done after other parts are settled. |
Ping @iBug |
This is the first of a series of more aggressive (i.e. most likely breaking) changes to
sshmux
to make it more extensive.log/slog
is a structured logging library introduced in Go 1.21, and the previous usage ofLogChannel
is a static case for structural logging. Migrating tolog/slog
will allow us to log with more precise control over different contexts, without the burden of managing astruct
for each case.For this specific pitch, all behavioral changes are addictive, and has been verified by local testing.
Follow-up for this pitch including integrating OpenTelemetry Logging support via OpenTelemetry SLog Log Bridge.