-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add the difference example of look with and without destructurama #18
Comments
not sure what i have to test more: module Tests
open Expecto
open System
open Serilog
open Serilog.Core
open Serilog.Context
open Serilog.Events
open Serilog.Formatting.Compact
open Destructurama.FSharp
let loggerWithJsonAndDestructure =
LoggerConfiguration()
.MinimumLevel.Is(LogEventLevel.Debug)
.Destructure.FSharpTypes()
.Enrich.FromLogContext()
.WriteTo.Console(
formatter = CompactJsonFormatter()
)
.CreateLogger() :> ILogger
let loggerWithJson =
LoggerConfiguration()
.MinimumLevel.Is(LogEventLevel.Debug)
.Enrich.FromLogContext()
.WriteTo.Console(
formatter = CompactJsonFormatter()
)
.CreateLogger() :> ILogger
type X = Y of int | Z of string
type R = {
A: int
B: string
}
type K = R * X
let r = {A = 42; B = "t"}
let k = (r, Y 27)
[<Tests>]
let tests =
testList "samples" [
test "u" {
let _ = LogContext.PushProperty("z", Y 13)
let _ = LogContext.PushProperty("l", "value")
loggerWithJsonAndDestructure.Fatal("{UnionDes}", Y 1)
loggerWithJson.Error("{Union}", Y 1)
Expect.isTrue true "true"
}
test "r" {
let _ = LogContext.PushProperty("f", {A = 12; B = "bbb"})
let _ = LogContext.PushProperty("l", "value")
loggerWithJsonAndDestructure.Fatal("{RecordDes}", {A = 1; B = "bDes"})
loggerWithJson.Error("{Record}", {A = 1; B = "b"})
Expect.isTrue true "true"
}
test "t" {
let _ = LogContext.PushProperty("o", k)
let _ = LogContext.PushProperty("l", "value")
loggerWithJsonAndDestructure.Fatal("{TupleDes}", k)
loggerWithJson.Error("{Tuple}", k)
Expect.isTrue true "true"
}
] with json
without
have not tested collections so. Not sure for usual console output, but I am searching for tool which will make F# objects look like JSON objects in JSON. So these are easily indexed but logging storages.
|
I completely agree with this. I came here to looking for the same comparison. It would also be nice to see the event in JSON format or specifically what it looks like in Seq (my favorite Serilog sink). |
Here is some more feedback about this. I added Looking more closely at the one example in the README (and combining it with what I think the output would have been without Is my impression accurate? The case data in the discriminated unions in my application at work are not suffering from primitive obsession. Instead, I create stronger types with single-case discriminated unions. This would explain why I was unable to find any logging in my application at work that was improved by |
I think the readme should be tweaked a bit. Assuming the code in the type Shape =
| Circle of Radius : double
| Rectangle of Width : double * Height : double
| Arc // ...
let shape = Circle 5.
Log.Information("Drawing a {@Shape}", shape) Note that the Without
With
|
@dzmitry-lahoda @TysonMN @Evangelink PR is welcome! |
This issue was marked as stale since it has not been active for a long time |
Case 1:
Case 2:
The text was updated successfully, but these errors were encountered: