Comments (6)
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
{"@t":"2020-01-30T12:55:49.1338020Z","@mt":"{UnionDes}","@l":"Fatal","UnionDes":"Y 1","l":"value","z":"Y 13"}
{"@t":"2020-01-30T12:55:49.1338020Z","@mt":"{RecordDes}","@l":"Fatal","RecordDes":"{ A = 1\n B = \"b\" }","l":"value","f":"{ A = 12\n B = \"bbb\" }"}
{"@t":"2020-01-30T12:55:49.1338820Z","@mt":"{TupleDes}","@l":"Fatal","TupleDes":"({ A = 42\n B = \"t\" }, Y 27)","l":"value","o":"({ A = 42\n B = \"t\" }, Y 27)"}
{"@t":"2020-01-30T12:55:49.1397800Z","@mt":"{Record}","@l":"Error","Record":"{ A = 1\n B = \"b\" }","l":"value","f":"{ A = 12\n B = \"bbb\" }"}
{"@t":"2020-01-30T12:55:49.1398150Z","@mt":"{Union}","@l":"Error","Union":"Y 1","l":"value","z":"Y 13"}
{"@t":"2020-01-30T12:55:49.1398910Z","@mt":"{Tuple}","@l":"Error","Tuple":"({ A = 42\n B = \"t\" }, Y 27)","l":"value","o":"({ A = 42\n B = \"t\" }, Y 27)"}
without
[15:56:29 FTL] ({ A = 42
B = "t" }, Y 27)
[15:56:29 FTL] { A = 1
B = "b" }
[15:56:29 FTL] Y 1
[15:56:29 ERR] { A = 1
B = "b" }
[15:56:29 ERR] Y 1
[15:56:29 ERR] ({ A = 42
B = "t" }, Y 27)
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.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="Sample.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Destructurama.FSharp" Version="1.1.1-dev-00035" />
<PackageReference Include="Expecto" Version="8.*" />
<PackageReference Include="FSharp.Core" Version="4.*" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0-dev-00839" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
</ItemGroup>
</Project>
from fsharp.
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).
from fsharp.
Here is some more feedback about this.
I added Destructurama.Fsharp
to my application at work, but I couldn't find any existing log call that was improved.
Looking more closely at the one example in the README (and combining it with what I think the output would have been without Destructurama.Fsharp
), the impression I get is that Destructurama.Fsharp
only improves the logging of discriminated unions that have case data that is both suffering from primitive obsession but also compensates for it by giving names to the fields.
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 Destructurama.Fsharp
.
from fsharp.
I think the readme should be tweaked a bit.
Assuming the code in the readme
:
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 @
is important to get it to work properly.
Without Destructurama.FSharp
:
2021-04-14 10:20:27.564 +02:00 [INF] Drawing a {"Radius":5,"Tag":0,"IsCircle":true,"IsRectangle":false,"IsArc":false,"$type":"Circle"}
With Destructurama.FSharp
:
2021-04-14 10:20:42.719 +02:00 [INF] Drawing a {"Radius":5,"$type":"Circle"}
from fsharp.
@dzmitry-lahoda @TysonMN @Evangelink PR is welcome!
from fsharp.
This issue was marked as stale since it has not been active for a long time
from fsharp.
Related Issues (16)
- Can a stable package version be published? HOT 2
- Consider using System.Reflection.Emit to generate per-type record and union cons/unconsers HOT 2
- Add project URL HOT 1
- Depreciate Destructurama.FSharp.NetCore? HOT 4
- Release version without upper bound on FSharp.Core HOT 5
- How to declare from app.config? HOT 2
- Add support for FSharp 5.0 HOT 2
- Weird results for Option, Result, anonymous types HOT 5
- list of lists throws InvalidCastException HOT 2
- Add CodeQL workflow back when supported HOT 1
- Add API approval tests HOT 1
- Increase code coverage to 100% HOT 1
- Looking for maintainers! HOT 6
- Untracked sources issue in nupkg HOT 4
- Built-in Result type not destructured HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharp.