near-runtime-ts
near-runtime-ts copied to clipboard
Improve logging interface
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.
Yeah this can be done easily with a generic function. See here.
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.
Do you mean like string interpolation?
Yes
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.
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.
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.