#Live logs
1 messages ยท Page 1 of 1 (latest)
There's ways to do it yes. First, if you're not using a module, dagger run will give you a nice TUI with live progress. You basically prefix your usual command with dagger run ....
I'm using the go SDK and embedding in another program. So TUI logs wont work for me. Currently it just hangs for a while and then dumps the logs
So im trying to see if there are any hooks i can use to access the live logs directly
@left jungle there's no native way of doing this. Here's something relatively safe you can do.
func main() {
ctx := context.Background()
c, _ := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
c.Container().From("alpine").WithExec([]string{"sh", "-c", "while true; do echo hello | sed 's/^/[SOME_PREFIX] /'; sleep 1; done"}).Stdout(ctx)
}
^ os.Stdout can be whatever Writer you need and then you can filter the logs you need by looking for SOME_PREFIX
are dagger modules and sdk supported with dagger run? because I thought run doesn't support modules as it's not sdk integrated
not yet but it's almost there https://github.com/dagger/dagger/pull/9531
That's what I was going to suggest next ๐, but I suggest using os.Stderr for logs, rather than os.Stdout.
yeah.. I think he should use his own writer
and then pipe to whatever he needs
But there's something else. The progress you see in dagger run is based on OpenTelemetry. So your app could have its own Otel exporter, even spitting to the screen if you want. It would integrate with Dagger's telemetry out of the box.
The WithLogOutput is a bit more lower level but ok if it works for you.
yep, there's also this. didn't want to bring it up since it involves adding a bit more complexity with the OTEL thing but if you need something at bigger scale, this is the way to go for sure
Yes but I also think it looks more complex than it is.
The otel option sounds interesting, any examples that you can point me to?