Skip to content

structured logging#59

Merged
rr0gi merged 16 commits intomasterfrom
sc/structured-logging
May 7, 2026
Merged

structured logging#59
rr0gi merged 16 commits intomasterfrom
sc/structured-logging

Conversation

@c-cube
Copy link
Copy Markdown
Contributor

@c-cube c-cube commented Apr 21, 2026

  • modifies how loggers work so it's easier to swap them at runtime
  • pass timestamp and a list of key/value pairs
  • normal callsites for logging are unaffected, but it enables us to have richer logging.

@c-cube c-cube force-pushed the sc/structured-logging branch from c2eced1 to 07ed94a Compare April 21, 2026 20:39
@c-cube c-cube force-pushed the sc/structured-logging branch from de9c75f to ba7e6f4 Compare April 28, 2026 14:34
@c-cube c-cube requested a review from rr0gi April 28, 2026 15:37
@c-cube c-cube marked this pull request as ready for review April 29, 2026 18:44
@c-cube c-cube force-pushed the sc/structured-logging branch from ba7e6f4 to c87470a Compare April 30, 2026 13:48
@c-cube
Copy link
Copy Markdown
Contributor Author

c-cube commented Apr 30, 2026

GHA/ocaml-setup is doing weird stuff, but otherwise it's ready for review.

@c-cube
Copy link
Copy Markdown
Contributor Author

c-cube commented May 4, 2026

will merge wed 5/6

Copy link
Copy Markdown
Contributor

@rr0gi rr0gi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't like that it changes the format of default logging
i would suggest having another parameter that keeps old message in default logfmt and uses pairs in rich (in addition to current ~pairs which i understand appends pairs to log message always)

Comment thread httpev.ml Outdated
let do_fork () =
match check_req req with
| `Error err -> Exn.fail "pre fork %s : %s" (show_request req) (Unix.error_message err)
| `Error err -> Exn.fail "pre fork : %s" (show_request req) (Unix.error_message err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Comment thread web.ml
let verbose_curl_result nr_http action t h code =
let open Curl in
let b = Buffer.create 10 in
bprintf b "%s #%d %s ⇓%s ⇑%s %s "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how will Web request log look like now?

@c-cube
Copy link
Copy Markdown
Contributor Author

c-cube commented May 5, 2026 via email

@c-cube c-cube requested a review from rr0gi May 6, 2026 13:58
@c-cube
Copy link
Copy Markdown
Contributor Author

c-cube commented May 6, 2026

Ok, the web and http logs should be back to (almost) exactly what they were, modulo a bit of punctuation (some ":" added). The logging is more uniform now, and checks what logging backend we use to log accordingly.

@c-cube c-cube force-pushed the sc/structured-logging branch from 06db0f7 to 0a08364 Compare May 6, 2026 14:03
Comment thread web.ml Outdated
Comment thread httpev.ml Outdated
Comment thread log.ml
Comment thread log.ml Outdated
Comment thread log.ml Outdated
Comment thread log.ml Outdated
Comment thread log.ml Outdated
Comment on lines +161 to +171
let debug_s = State.logger.debug_s
let info_s = State.logger.info_s
let warn_s = State.logger.warn_s
let error_s = State.logger.error_s
let critical_s = State.logger.critical_s
let put_s = State.logger.put_s
let debug = State.logger.debug
let info = State.logger.info
let warn = State.logger.warn
let error = State.logger.error
let critical = State.logger.critical
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to export these here, they are overridden below with make_s

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ones below are only visible within the class, they're not at toplevel. But I could remove debug_s, info_s, etc as they might not be super useful?

Comment thread logger.ml Outdated
in { put }

(** A logger *)
type t = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also do we even need this 🤔
single put_s function would be "easier" for Log.log to build upon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so just use the type put above? can do

@rr0gi rr0gi merged commit 4efc8ba into master May 7, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants