messagetemplates / messagetemplates-fsharp

Message templates - the ability to format named string values, and capture the properties
http://messagetemplates.org/
Apache License 2.0
18 stars 4 forks source link

Decide how destructuring and capturing should work #9

Closed adamchester closed 9 years ago

adamchester commented 9 years ago

The F# implementation currently doesn't do anything much in this area (the tests are explicitly ignored right now). The C# implementation is based on serilog and does whatever Serilog did.

This comment from @nblumhardt is interesting:

For most property types, e.g. Name above, representing them as a simple scalar "nblumhardt", 42, or array-of-scalars, is fine and doesn't require any special types. It's less clear what an @-destructured value should be Capture()d as. Serilog has StructureValue and friends to snapshot object state in a way that makes concurrent access safe (and caches the reflection/allocation done in that process).

For my purposes, this seems quite important. If some library (eg. suave) needs to log the property values associated with a structured message template, it needs to be able capture them into a reasonable structured format.

What's interesting in F# land is that many core types (such as records and lists) are immutable by default, but records (for example) can be made mutable by either having mutable fields or using the CLIMutable attribute. I think this means the F# context is no different to serilog. Anything that needs to be logged/captured by MessageTemplates is potentially mutable, and many bad things would happen if the values are changed by another thread.

I wonder if there should be a way to avoid the copy of the objects if the template owner knows they're immutable? I wonder how ugly it would get when they make a mistake?

nblumhardt commented 9 years ago

No insights to add, but just for the sake of a second opinion I'd favour the safer and simpler option. Seems like an optimisation could be added down the track in a potentially non-breaking way if needed. So far hasn't been requested of Serilog. YMMV ;-)

adamchester commented 9 years ago

I think I'm happy with doing things the way Serilog does, and I think I'm not too far away from doing the same in the F# version over in #14, so I'm closing this :)