WebAssembly / wasi-logging

WASI logging API
19 stars 5 forks source link

The `log` function should be passed in a structure #18

Open oovm opened 6 months ago

oovm commented 6 months ago

I think the log function should take a record logging {...} as input.

If the downstream wants to define log events and retrieve data, the best way is to directly import the logging type.

sunfishcode commented 6 months ago

If I understand what you're suggesting, this would require generics in the language, which we don't have yet.

It may also be instructive to think through how this would work even if we could do it. Instead of a single log interface that many producers and consumers could share, this would imply many different log interfaces. Producers that know about one record type wouldn't be compatible with consumers that use a different record type. The advantage of using a common wasi-logging interface would go away, compared to just having everyone use custom logging interfaces.

oovm commented 6 months ago

Sorry, my meaning may be ambiguous, it is not that complicated.

My focus is on how to make it more convenient to read and decide whether to display the message field based on the level field of the log event.

Rather than using it as a function parameter, defining record is a better choice

// interface logging {
//     log: func(level: level, context: string, message: string);
// }
interface logging {
    record logging {
        level: level, 
        context: string, 
        message: string
    }

    log: func(input: logging);
}

Again, I am not considering any subtyping or extensibility issues in this issue.

sunfishcode commented 6 months ago

Ah, ok. That is indeed much simpler. However, it's not clear what advantage that has. Could you sketch out more of what kind of code you'd want to write using this?