Project

dbg-rb

0.02
The project is in a healthy, maintained state
Rust-inspired, puts debugging helper, adding caller info and optional coloring.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

>= 0
 Project Readme

dbg Gem Version GH Actions

Dbg base

Because I wrote:

p '!!!!!!!!!!!!!!!'
p msg
p '!!!!!!!!!!!!!!!'

too many times already.

dbg is a minimal, Rust inspired, puts debugging command for Ruby. It provides caller context and formatting helpful in everyday debugging tasks.

Installation

bundle add dbg-rb

Alternatively, you can use an inline version of dbg-rb without adding it to the Gemfile. Check out this post for info on how to do it.

Usage

Gem adds a global dbg method that you can use for puts debugging:

require "dbg-rb"

dbg(User.last.id)
# [web/user_sessions_controller.rb:37] User.last.id = 1972

It appends a caller file, line info and source expression to the debug output.

Hash values are pretty printed:

dbg(User.last.as_json)
# [web/users_controller.rb:10] User.last.as_json = {
#   "id": 160111,
#   "team_id": 1,
#   "pseudonym": "Anonymous-CBWE",
#   ...
# }

You can color the output:

config/initializers/dbg_rb.rb

require "dbg-rb"

DbgRb.color_code = 33 
# 31 red 
# 32 green 
# 33 yellow 
# 34 blue 
# 35 pink 
# 36 light blue

It's yellow by default. You can disable colors by running:

DbgRb.color_code = nil
dbg(User.last(2).map(&:as_json))

Dbg color

If it does not stand out enough, you can enable dbg highlighting:

config/initializers/dbg_rb.rb

require "dbg-rb"

DbgRb.highlight!("πŸŽ‰πŸ’”πŸ’£πŸ•ΊπŸš€πŸ§¨πŸ™ˆπŸ€―πŸ₯³πŸŒˆπŸ¦„")

Dbg emoji

Logs integration

Lbg logs

Use lbg to send debug output through a logger instead of stdio:

require "dbg-rb"

lbg(User.last.id)
# Sends to Rails.logger.debug: [web/user_sessions_controller.rb:37] User.last.id = 1972

The lbg method:

  • Uses Rails.logger by default when Rails is available
  • Falls back to regular dbg behavior if no logger is configured
  • Uses :debug log level by default

You can configure a custom logger and log level:

DbgRb.logger = MyLogger.new
DbgRb.log_level = :info

Status

Contributions & ideas very welcome!