Skip to content

Instantly share code, notes, and snippets.

@blair55
Created November 29, 2022 12:55
Show Gist options
  • Save blair55/8b882d5056c6b0bbd32abb8df477230c to your computer and use it in GitHub Desktop.
Save blair55/8b882d5056c6b0bbd32abb8df477230c to your computer and use it in GitHub Desktop.
Logging example before applying writer
let getSuperUserData (super, log: Logger) =
let sw = Stopwatch.StartNew()
let service = getService ()
let result = service.getSuperUserDetails super
log.info ({| serviceElapsed = sw.ElapsedMilliseconds |})
match result with
| Ok res ->
log.info ({| serviceResult = "success" |})
Some res
| Error e ->
log.info ({| serviceResult = "error"; error = e |})
None
let doWork (input, log: Logger) =
let sw = Stopwatch.StartNew()
log.info ({| userId = input.UserId |})
match input.Status with
| Valid -> log.info ({| status = "valid" |})
// ...
| Invalid -> log.info ({| status = "invalid" |})
// ...
let result =
match input.Subscription with
| Basic -> None
| Super super -> getSuperUserData (super, log)
log.info ({| totalElapsed = sw.ElapsedMilliseconds |})
// ...
result
[<EntryPoint>]
let main input =
let log = getLogger ()
doWork (input, log) |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment