near-runtime-ts icon indicating copy to clipboard operation
near-runtime-ts copied to clipboard

Improve logging interface

Open bowenwang1996 opened this issue 5 years ago • 7 comments

Currently the function available function for logging is log which takes a string. It would be better if we can support logging of struct without having to call .encode explicitly. I am not sure how exactly this can be done given the constraint of assemblyscript (there is no macro for example), but it's something that we should keep in mind.

bowenwang1996 avatar Feb 16 '20 18:02 bowenwang1996

Yeah this can be done easily with a generic function. See here.

willemneal avatar Feb 17 '20 15:02 willemneal

That helps but is still not ideal. Ideally you want something like rust's println macro that allows you to easily mix message with structs.

bowenwang1996 avatar Feb 17 '20 16:02 bowenwang1996

Do you mean like string interpolation?

willemneal avatar Feb 17 '20 16:02 willemneal

Yes

bowenwang1996 avatar Feb 17 '20 16:02 bowenwang1996

Ah well then @ailisp and I have been working on that separately. We can easily add a default toString method for each reference type to get its JSON string. So for now I say that we can provide the toString and then users will still have to use concatenation while we finish up adding interpolation to upstream.

willemneal avatar Feb 17 '20 16:02 willemneal

That's good enough for now. The problem right now is that people are not aware of the .encode method so they cannot log an object easily.

bowenwang1996 avatar Feb 17 '20 16:02 bowenwang1996

Yeah we need to add a section of setting up the typing environment. @amgando and I can meet about it in the near future, (hehe near ;-) ). It the types file here I was able to inject the methods into any reference type. However, if you don't add this file to your local setup through the use of /// <refercence types="near-runtime-ts/assemblys/as_types" /> then the IDE doesn't hint that this method is possible.

willemneal avatar Feb 17 '20 16:02 willemneal