destructurama / fsharp Goto Github PK
View Code? Open in Web Editor NEWNative support for destructuring F# types when logging to Serilog.
License: Apache License 2.0
Native support for destructuring F# types when logging to Serilog.
License: Apache License 2.0
Consider this:
let data = {| Data = "This is a test"; Sub = {| Foo = Ok 1; Bar = [Some 2] |} |}
Log.Information("Data: {@Data}", data)
I get this:
{"Data": "This is a test", "Sub": {"Bar": [{"Value": 2, "$type": "Some"}], "Foo": {"ResultValue": 1, "$type": "Ok"}, "$type": "<>f__AnonymousType2950936943`2"}, "$type": "<>f__AnonymousType2576086083`2"}
There are several issues:
"$type": "Some"
for Option
seems weird"$type": "Ok"
for Result
seems weird"$type": "<>f__AnonymousType..."
should not be thereIdeally, IMHO, for unions, you'd use a format like https://github.com/Tarmil/FSharp.SystemTextJson with union encoding set to
JsonUnionEncoding.Default
||| JsonUnionEncoding.InternalTag
||| JsonUnionEncoding.NamedFields
// And perhaps also this
||| JsonUnionEncoding.UnwrapFieldlessTags
I would therefore want something like this:
{"Data": "This is a test", "Sub": {"Bar": [2], "Foo": {"Case": "Ok", "ResultValue": 1}}}
I understand that this package is old and not actively maintained. I may end up writing my own library to destructure F# types.
See https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/
F# is not supported.
Hi. I'm C# developer and last month I helped with updating the codebase/CI of the repositories in destructurama org. This repo is the last one among them. I can’t post PRs myself - I have no necessary knowledge and time, but I can continue to help. So if someone is ready to help, I will be glad.
I was confused by the difference between Destructurama.FSharp
and Destructurama.FSharp.NetCore
on nuget.org until I saw that the latter hadn't been updated for several years. I think it would be better if its documentation was similar to Serilog.Extras.FSharp
, which says it is deprecated and that Destructurama.FSharp
should be used instead.
@nblumhardt now that there's a prerelease out and it's been baking for a few months (https://www.nuget.org/packages/Destructurama.FSharp/1.1.0-dev-00023), would it be possible to push a stable version? If not, are there things I can knock out to make that possible?
I think the NuGet package does not include a project URL (that links back to this repo).
Using the test script, I get the an InvalidCastException
:
>fsi lists.fsx
System.InvalidCastException: Unable to cast object of type 'Microsoft.FSharp.Collections.FSharpList`1[System.Int32]' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.
at Destructurama.FSharp.FSharpTypesDestructuringPolicy.Serilog-Core-IDestructuringPolicy-TryDestructure(Object value, ILogEventPropertyValueFactory propertyValueFactory, LogEventPropertyValue& result) in C:\projects\fsharp\src\Destructurama.FSharp\DestructuramaFSharp.fs:line 31
at Serilog.Parameters.PropertyValueConverter.CreatePropertyValue(Object value, Destructuring destructuring, Int32 depth) in c:\projects\serilog\src\Serilog\Parameters\PropertyValueConverter-net40.cs:line 121
at Serilog.Parameters.PropertyValueConverter.DepthLimiter.CreatePropertyValue(Object value, Boolean destructureObjects) in c:\projects\serilog\src\Serilog\Parameters\DepthLimiter.cs:line 45
at [email protected](b& )
at Microsoft.FSharp.Collections.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Serilog.Events.SequenceValue..ctor(IEnumerable`1 elements) in c:\projects\serilog\src\Serilog\Events\SequenceValue-net40.cs:line 37
at Destructurama.FSharp.FSharpTypesDestructuringPolicy.Serilog-Core-IDestructuringPolicy-TryDestructure(Object value, ILogEventPropertyValueFactory propertyValueFactory, LogEventPropertyValue& result) in C:\projects\fsharp\src\Destructurama.FSharp\DestructuramaFSharp.fs:line 33
at Serilog.Parameters.PropertyValueConverter.CreatePropertyValue(Object value, Destructuring destructuring, Int32 depth) in c:\projects\serilog\src\Serilog\Parameters\PropertyValueConverter-net40.cs:line 121
at Serilog.Parameters.PropertyBinder.ConstructProperty(PropertyToken propertyToken, Object value) in c:\projects\serilog\src\Serilog\Parameters\PropertyBinder.cs:line 122
at Serilog.Parameters.PropertyBinder.ConstructNamedProperties(MessageTemplate template, Object[] messageTemplateParameters) in c:\projects\serilog\src\Serilog\Parameters\PropertyBinder.cs:line 113
at Serilog.Parameters.PropertyBinder.ConstructProperties(MessageTemplate messageTemplate, Object[] messageTemplateParameters) in c:\projects\serilog\src\Serilog\Parameters\PropertyBinder.cs:line 57
at Serilog.Core.Pipeline.Logger.Write(LogEventLevel level, Exception exception, String messageTemplate, Object[] propertyValues) in c:\projects\serilog\src\Serilog\Core\Pipeline\Logger.cs:line 138
at Serilog.Core.Pipeline.Logger.Verbose(String messageTemplate, Object[] propertyValues) in c:\projects\serilog\src\Serilog\Core\Pipeline\Logger.cs:line 177
at <StartupCode$FSI_0001>.$FSI_0001.main@() in C:\repo\fserilog\serilog.fsx:line 40
Stopped due to error
The test script is:
#I "packages/Serilog/lib/net40"
#r "Serilog"
#r "Serilog.FullNetFx"
#I "packages/Destructurama.FSharp/lib/portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10"
#r "Destructurama.FSharp"
open Serilog
Log.Logger <- LoggerConfiguration()
.Destructure.FSharpTypes()
.WriteTo.ColoredConsole()
.MinimumLevel.Verbose()
.CreateLogger()
let myListOfLists = [
[1;2;3;4;5]
[6;7;8;9;10]
]
Log.Verbose("List of lists {@list}", myListOfLists)
I used the following nuget package versions:
NUGET
remote: https://nuget.org/api/v2
specs:
Destructurama.FSharp (1.0.8)
Serilog (>= 1.4.204)
Serilog (1.5.6)
The FSharp.Reflection members are slow and allocate-y. It would be great to mimic the approach used in Tarmil/FSharp.SystemTextJson#15 to make these much faster/more useful.
See PublicApiGenerator
usage in other destructurama repos.
Hi,
I could not find how to declare the .Destructure.FSharpTypes()
part inside the app.config
file. Any idea how to?
Case 1:
Case 2:
The FSharp.Core built-in Result
type (defined here) is not destructured correctly:
Microsoft.FSharp.Core.FSharpResult`2[System.String,System.Object]
It seems it only runs ToString
on it. I would expect this to be destructured the same way as other unions.
The constraint on FSharp.Core
was relaxed in PR #13. However, a (non pre-) release has not been created that includes that change. The latest release version available on nuget.org is 1.1.0
, which still requires FSharp.Core
to have a version strictly less than 4.7.0
. The two prereleases on nuget.org after version 1.1.0
are versions 1.1.1-dev-00033
and 1.1.1-dev-00035
, and neither includes restricts FSharp.Core
from above.
Can a new release of Destructurama.FSharp
be made that does not include the upper bound constraint on FSharp.Core
?
I am having this warning when using C# 5.0:
warning NU1608: Detected package version outside of dependency constraint: Destructurama.FSharp 1.1.0 requires FSharp.Core (>= 4.6.2 && < 4.7.0) but version FSharp.Core 5.0.0 was resolved
But everything seems to be working fine.
Can the upper bound constraint be bumped?
Current coverage is 71% - https://app.codecov.io/gh/destructurama/fsharp
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.