Overview
When executing commands on a Devbox, you have two primary ways to access logs:- Log Streaming: Receive stdout and stderr output in real-time as the command runs
- Completed Execution Logs: Retrieve the full output after a command has finished
Real-Time Log Streaming
For long-running commands like builds, tests, or servers, you can stream output as it’s generated using callback functions.Streaming Combined Output
Use theoutput callback to receive both stdout and stderr combined:
Streaming Stdout and Stderr Separately
For more control, use separate callbacks for stdout and stderr:Streaming is ideal for commands where you want immediate feedback, such as build processes, test suites, or log tailing.
By default, commands execute in the
/home/user directory. Use Named Shells to maintain a working directory across multiple commands.Streaming with Named Shells
Named shells also support log streaming:Getting Logs from Completed Executions
After a command finishes, you can retrieve the complete stdout and stderr output, or just the last N lines.Retrieving Full Output
Retrieving Last N Lines
When you only need the most recent logs, you can specify the number of lines to retrieve. This is more efficient as it avoids fetching the entire output:Specifying
numLines resolves faster than fetching all logs, especially for commands with verbose output. Use this when you only need to check the final status or recent errors.Retrieving Logs from Async Executions
For commands started withexec_async, you can wait for completion and then retrieve logs:
Combining Streaming and Final Logs
You can stream logs in real-time while still having access to the complete output after execution:Best Practices
Use Streaming for Long-Running Commands
For commands that take more than a few seconds, streaming provides immediate feedback:Store Logs for Debugging
When running automated workflows, store logs for later analysis:Handle Errors Gracefully
Use thesuccess or failed properties to check execution status, or check the exit code directly:
For more information about command execution, see the Execute Commands documentation. For stateful shell sessions, see Named Shells.
