1 # Application-only or actual transport completion, with a closed safe access projection. 2 import Base 3 import bend-kit-time@0.2.0.0/time.bend as Time 4 import bend-kit-int@0.2.0.0/int.bend as Int 5 import bend-kit-http@0.35.0.0/completion.bend as Transport 6 import bend-kit-notch@0.2.0.0/notch.bend as Notch 7 8 type Outcome is Data: 9 ApplicationOnly{} 10 Transport{outcome: Transport.Outcome} 11 12 type Notice is Data: 13 Notice{status: U32, duration: Time.Duration, mapped: Bool, stopped: Bool, outcome: Outcome} 14 15 # No caller-supplied logger context or request fields can enter an access line. 16 type Access is Data: 17 Disabled{} 18 Enabled{format: Notch.Format} 19 20 def outcome.name(outcome: Outcome) -> String: 21 match outcome: 22 case ApplicationOnly{}: "application_only" 23 case Transport{Transport.HostAccepted{}}: "host_accepted" 24 case Transport{Transport.WriteFailed{code, message}}: "write_failed" 25 case Transport{Transport.IncompleteResponse{}}: "incomplete_response" 26 27 def access(config: Access, notice: Notice) -> IO(Unit): 28 match config: 29 case Disabled{}: IO.pure(Unit, Unit{}) 30 case Enabled{format}: 31 Notice{status, duration, mapped, stopped, outcome} = notice 32 Notch.info(Notch.Logger{Notch.Info{}, format, Nil{}}, "access", 33 [Notch.num("status", status), Notch.str("duration_ms", Int.I64.show(Time.Duration.to_ms(duration))), 34 Notch.flag("mapped", mapped), Notch.flag("stopped", stopped), Notch.str("outcome", outcome.name(outcome))])