-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sdk): add print function to create console output without a trialing newline #5379
Conversation
Thanks for opening this pull request! 🎉
|
Console preview environment is available at https://wing-console-pr-5379.fly.dev 🚀 Last Updated (UTC) 2024-01-01 07:28 |
BenchmarksComparison to Baseline 🟥⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜
⬜ Within 1.5 standard deviations Benchmarks may vary outside of normal expectations, especially when running in GitHub Actions CI. Results
Last Updated (UTC) 2024-01-01 07:36 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced that this use case entitles a whole new built in function. We are trying to minimize those as much as possible.
Maybe something like fs.stdout.write("text")
work?
examples/tests/valid/log.test.w
Outdated
bring cloud; | ||
|
||
|
||
log("preflight log"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to test under sdk_tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. interestingly, this was already in valid
but you're right, sdk_tests
makes much more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like fs.stdout.write("text") work?
yes, that would certainly work (i have been doing the equivalent). thought i completely understand the goal to minimize, i think any language that supports basic output (as Wing does with log()
) should do the same without a newline (just MHO).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about?
log("foo", newline: false);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bit of context: logging in wing doesn't have the same semantic meaning as printing to standard error, standard output in traditional programming, languages.
There's also a big difference between preflight and inflight.
In preflight logs are basically part of the compilation output while in inflight logs are emitted from the runtime code, executed on the cloud in various computation platforms, such as lambda containers, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i gave it a try (spending most of today messing with it) but didn't have any real success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mortax really appreciate the efforts!
@Chriscbr or @yoav-steinberg will be able to help.
alternatively - if you are comfortable with implementing this as a standard library function in the meantime, so that you are unblocked, then go ahead and we can discuss the built-in support in log()
separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @eladb. i can wait until it can be done properly. i have my own workaround for now so it's not worth expending effort for something temporary.
i'm ready to do the bulk of the work -- i just need a gentle shove in the right direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're on the right track @mortax. To get the newline
parameter working, I think you'll need to add a new struct type. The reason's that in Wing, named parameters are implemented by providing a struct as the last parameter in any function or constructor. So it will be as if we defined the log
function like
let log = (message: str, opts: LogOptions) => { ... }
but callers can use it any of these ways:
log("foo");
// or
log("foo", newline: false);
// or
log("foo", LogOptions { newline: false });
I'd suggest maybe going about this by adding a struct through the Wing SDK, which is implemented as a TypeScript interface. Here's an example of another one:
wing/libs/wingsdk/src/std/json.ts
Lines 3 to 9 in 2ca491b
/** | |
* Options for stringify() method. | |
*/ | |
export interface JsonStringifyOptions { | |
/** Indentation spaces number */ | |
readonly indent: number; | |
} |
std
would be a good place for this. Once the interface is added there, you can update the code where builtins are added. (It was in lib.rs
but it was recently moved to type_check.rs
- look for the add_builtins
function).
Let me know that helps or if you run into any issues!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. i'll try to give this a try tomorrow.
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Signed-off-by: monada-bot[bot] <monabot@monada.co>
Hi, This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days. |
This PR implements the real solution to the issue raised in discussion #1772:
print()
to generate console output without a trailing newlineNote that I have not included
println()
since it would be the same aslog()
.By submitting this pull request, I confirm that my contribution is made under the terms of the Wing Cloud Contribution License.