Trinidad 1.4.4开发环境日志配置及Pry调试适配咨询
Hey there! I've run into this exact issue with Trinidad 1.4.4 and Pry in development, so let's cover both your requested solutions—configuring Trinidad to use log files like production, and Pry-specific workarounds to avoid stdout conflicts.
Option 1: Configure Trinidad to Write Logs to a File in Development
Trinidad's default dev behavior pushes all output to stdout, but you can override this via configuration. Here are two ways to do it:
Using a
trinidad.ymlconfig file
Create or edit atrinidad.ymlfile in your project root, and add the development environment settings:development: logger: file: log/development.log level: info # Optional: Adjust to debug/warn/error as needed stdout: false # Disables default stdout output to keep logs in the fileWhen you start Trinidad now, all server logs will go straight to
log/development.loginstead of cluttering your terminal, leaving it free for Pry interactions.Using Ruby code configuration
If you prefer to set this up inconfig/trinidad.rbinstead of a YAML file, add this block:Trinidad.configure do |config| next unless config.environment == :development config.logger = { file: 'log/development.log', level: Logger::INFO } config.stdout = false end
Option 2: Pry Workarounds (Skip Log Configuration)
If you don't want to tweak Trinidad's logging setup right now, these Pry-focused fixes will let you debug without stdout interference:
Temporarily redirect stdout for
binding.pry
Right before yourbinding.prycall, switch stdout back to the terminal, then restore it after debugging:# Save original stdout (where Trinidad sends logs) original_stdout = $stdout # Redirect to terminal for Pry $stdout = STDOUT binding.pry # Restore original stdout after exiting Pry $stdout = original_stdoutThis keeps Pry's interaction clean in your terminal, while Trinidad logs continue to flow as usual (you might see a tiny bit of overlap, but it's minimal).
Use
pry-remotefor a detached debug session
This is my go-to workaround—pry-remoteruns Pry in a separate session, completely isolated from Trinidad's stdout:- Add the gem to your development group in Gemfile:
gem 'pry-remote', group: :development - Run
bundle install - Replace
binding.prywithbinding.remote_pryin your code - Start Trinidad, then open a new terminal window and run
pry-remote—you'll connect directly to the debug session with zero log interference.
- Add the gem to your development group in Gemfile:
Terminal split-screen (quick and dirty)
If you use a terminal with split-screen support (like iTerm2 or tmux), run Trinidad in one pane and keep an empty pane for Pry. While not as clean as the other options, it lets you separate log output from debug interactions.
内容的提问来源于stack exchange,提问作者Oleg Bulkin

