Skip to content
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

cmd: clean up generate stdout/stderr #439

Closed
egtann opened this issue Jan 19, 2024 · 3 comments
Closed

cmd: clean up generate stdout/stderr #439

egtann opened this issue Jan 19, 2024 · 3 comments
Labels
cmd enhancement New feature or request NeedsDecision Issue needs some more discussion so a decision can be made

Comments

@egtann
Copy link

egtann commented Jan 19, 2024

First off, thank you for this amazing tool. I am loving the experience with templ so far! I do have some small ideas which would improve quality of life when using templ generate.

There's two small improvements to the UX of the CLI tool that we can make:

1, stdout

Each time templ generate runs, it sends a very large amount of text to stdout on success. This is at odds with how most Unix and Go tools work, since those generate no output on success. Ideally templ generate would behave like other tools and not output hundreds of lines on every build in a large project, as this effectively wipes my terminal on each run given how many lines it outputs.

If we want to output debug information like how long every file took to generate, that should be under a verbose flag.

To work around this, I've started using templ generate 1>/dev/null in a Makefile, but this leads me to my next issue.

2. stderr

Failures/errors are outputted to stdout, so when I get an error, if I'm discarding the noise from stdout, I get no output or an unhelpful error:

$ templ generate 1>/dev/null
# <there's no output if it errors>

$ make templ
make: *** [Makefile:2: templ] Error 1
@egtann egtann changed the title generate: clean up stdout/stderr cmd: clean up generate stdout/stderr Jan 19, 2024
@a-h
Copy link
Owner

a-h commented Jan 23, 2024

Good points. I'd be up for a redesign of the templ output.

I like to see the feedback that "stuff is happening", especially in watch mode, but it is a little noisy. It outputs so much that it obscures any application logging output that's happening at the same time.

I'd really like to see something like a bubbletea style interface for interactive sessions (https://github.com/charmbracelet/bubbletea) where you can see a short summary of whether templ is working, and maybe show/hide your own application logging too. In the interactive mode, it would probably show something like the last time it ran (5 seconds ago etc.), how long each run is estimated to take, when the app was last restarted, a progress bar if it's running a generate, a tail of the underlying app logs, and maybe the last few HTTP request/response operations from the proxy.

Along with that (as the default), a --plain flag would be useful (probably more your style?), where there's minimal output with no bubbletea style interface.

So, support two modes, interactive, and a plain version for CI/CD and integration into other workflows.

@joerdav joerdav added enhancement New feature or request cmd NeedsDecision Issue needs some more discussion so a decision can be made labels Jan 30, 2024
@a-h
Copy link
Owner

a-h commented Jan 31, 2024

I've introduced a new structured logger, with a custom colourised handler in #470 while I was rewriting everything.

I thought that a fancy TUI was overkill once the output was tidied up. By default, it logs at Info level, so the default output is much simpler, just providing a summary.

$ templ generate
(✓) Complete [ updates=54 duration=87.295806ms ]

It's now under a verbose flag. You can set -v for debug mode, or set the level to "warn", "error" etc.. with the -log-level flag if you want no output at all unless there's errors.

However, I've kept the logs on stdout, since go's slog handler only has the choice of one and the logs are the program output.

@a-h
Copy link
Owner

a-h commented May 26, 2024

Update on this one. Decided to log to stderr, since it affects Bazel and other users to log to stdout.

#753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd enhancement New feature or request NeedsDecision Issue needs some more discussion so a decision can be made
Projects
None yet
Development

No branches or pull requests

3 participants