-
Notifications
You must be signed in to change notification settings - Fork 4
Debugging
Albert Álef edited this page Feb 3, 2026
·
3 revisions
RubyShell provides debug mode for detailed command execution logging.
Enable debug mode for a specific block of commands:
sh(debug: true) do
mkdir("test")
cd("test") do
touch("file.txt")
end
endEnable debug mode for a single command using the _debug option:
sh.echo("hello", _debug: true)Enable debug mode for all commands:
RubyShell.debug = true
sh.echo("hello") # Will output debug info
sh.ls # Will output debug info
RubyShell.debug = false # Disable when doneWhen debug mode is enabled, each command logs:
Executed: echo hello
Duration: 0.000312s
Pid: 12345
Exit code: 0
Stdout: "hello"
| Field | Description |
|---|---|
| Executed | The shell command that was run |
| Duration | Execution time in seconds |
| Pid | Process ID of the command |
| Exit code | Exit status (0 = success) |
| Stdout | The command output |
By default, debug output goes to $stdout. You can configure a custom logger:
# Use a file logger
RubyShell.logger = Logger.new("rubyshell.log")
# Set log level
RubyShell.log_level = :debug # :debug, :info, :warn, :errorDebug mode works with command chains too:
sh(debug: true) do
chain { cat("file.txt") | grep("error") | wc("-l") }
endEach command in the pipeline will be logged individually.
Next: Snippets