{"id":15512428,"url":"https://github.com/rdnewman/loba","last_synced_at":"2025-07-14T08:31:22.625Z","repository":{"id":47271873,"uuid":"48777976","full_name":"rdnewman/loba","owner":"rdnewman","description":"Easy tracing for debugging. Handy methods for adding trace lines to output or Rails logs.","archived":false,"fork":false,"pushed_at":"2024-09-09T17:09:44.000Z","size":197,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T05:12:52.295Z","etag":null,"topics":["debugging-tool","gem","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rdnewman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-30T02:48:05.000Z","updated_at":"2024-09-09T16:58:05.000Z","dependencies_parsed_at":"2024-08-10T17:41:58.531Z","dependency_job_id":"a63ebe6a-c2d9-4242-b12d-74f1af47431f","html_url":"https://github.com/rdnewman/loba","commit_stats":{"total_commits":107,"total_committers":2,"mean_commits":53.5,"dds":"0.25233644859813087","last_synced_commit":"c0cd70717f999ae3183229c8f1002f8f95b70309"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/rdnewman/loba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdnewman%2Floba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdnewman%2Floba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdnewman%2Floba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdnewman%2Floba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rdnewman","download_url":"https://codeload.github.com/rdnewman/loba/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdnewman%2Floba/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265262599,"owners_count":23736427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugging-tool","gem","ruby","ruby-gem"],"created_at":"2024-10-02T09:53:38.595Z","updated_at":"2025-07-14T08:31:22.202Z","avatar_url":"https://github.com/rdnewman.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Loba\n\n[![Gem Version](https://badge.fury.io/rb/loba.svg)](https://badge.fury.io/rb/loba)\n[![Build Status](https://github.com/rdnewman/loba/actions/workflows/ruby.yml/badge.svg?branch=main)](https://github.com/rdnewman/loba/actions?query=branch%3Amain++)\n[![Code Climate](https://codeclimate.com/github/rdnewman/loba/badges/gpa.svg)](https://codeclimate.com/github/rdnewman/loba)\n[![Test Coverage](https://codeclimate.com/github/rdnewman/loba/badges/coverage.svg)](https://codeclimate.com/github/rdnewman/loba/coverage)\n\n![Loba is \"write\" in Zulu](readme/zulu.png)\n\nEasy tracing for debugging: handy methods for adding trace lines to output (or logs).\n\n(Installation is pretty much what you'd expect for a gem, but read Environment Notes below first.)\n\n## Overview\n\nThere are two kinds of questions I usually want to answer when trying to diagnose code behavior:\n\n1. Is this spot of code being reached (or is it reached in the order I think it is)?\n1. What is the value of this variable?\n\nLoba statements are intended to be terse to minimize typing.\n\nLoba statements are intended to be minimally invasive and atomic. They should have negligible impact over regular `puts` or logging statements.\n\nLoba statements are expected to be removed when you're done with them. No point in cluttering up production code.\n\nLoba will generally always write to `$stdout` (i.e., `puts`). In addition to `$stdout`, Loba can also be made to write to a log (:debug). Writing to `$stdout` can be overridden.\n\nLoba will work equally well with or without Rails. If Rails is present and writing to a log is wanted, it will use the Rails log (e.g., `Rails.logger.debug`).\n\nLoba uses the [rainbow gem](https://rubygems.org/gems/rainbow) to help make trace statements more visible.\n\n## Usage\n\nAligning Loba statements to the far left in your source code (a la `=begin` or `=end`) will make them easier to see and remove when you're done. You may though find this somewhat annoying to do if your editor auto-indents.\n\n#### Timestamp notices:  `Loba.ts`\n\nOutputs a timestamped notice, useful for quick traces to see the code path and easier than, say, [Kernel#set_trace_func](http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-set_trace_func). Also does a simple elapsed time check since the previous timestamp notice to help with quick, minimalist profiling.\n\nFor example,\n\n```text\n[TIMESTAMP] #=0002, diff=93.478016, at=1451444972.970602     (in=/home/usracct/src/myapp/app/models/target.rb:55:in `some_calculation')\n```\n\nTo invoke,\n\n```ruby\nLoba.ts    # or with optional keyword arguments\n```\n\n`Loba.timestamp` is an alias for `Loba.ts`.\n\nYou can read [more detail](readme/ts.md) on this command.\n\n#### Variable or method return inspection:  `Loba.val`\n\nWrites line to `$stdout` (or optionally to a log, `logger.debug`) showing value with method and class identification.\n\n```ruby\nLoba.val :var_sym   # the :var_sym argument is the variable or method name given as a symbol\n```\n\nFor example,\n\n```text\n[Target.some_calculation] my_var: 54       (in /home/usracct/src/myapp/app/models/target.rb:55:in `some_calculation')\n```\n\nYou can read [more detail](readme/val.md) on this command.\n\n#### Output and logging options\n\nThere are several options to control where Loba writes its output:\n* `out`: controls whether `puts` to `$stdout` occurs (default: `true`)\n* `log`: controls whether logging occurs (default: `false`)\n* `logger`: controls which logger is used\n* `logdev`: in non-Rails environments, another way to direct where logging occurs\n\nYou can read [more detail](readme/log.md) about how to use these options.\n\n#### Snippet example\n\n```ruby\nrequire 'loba'    # not generally necessary in Rails projects\nclass HelloWorld\n  def initialize\n    @x = 42\nLoba.ts          # Loba statement put to the far left as a reminder to remove when done\n    @y = \"Charlie\"\n  end\n\n  def hello\nLoba.val :@x\n    puts \"Hello, #{@y}\" if @x == 42\nLoba.ts\n  end\nend\nHelloWorld.new.hello\n```\n\nOutput:\n\n```text\n[TIMESTAMP] #=0001, diff=0.000463, at=1451615389.505411   (in=/home/usracct/src/lobademo/hello_world.rb:4:in 'initialize'\n[HelloWorld#hello] @x: 42       (in /home/usracct/src/loba/spec/hello_world.rb:9:in `hello')\nHello, Charlie\n[TIMESTAMP] #=0002, diff=0.000720, at=1451615389.506132   (in=/home/usracct/src/lobademo/hello_world.rb:11:in 'hello'\n```\n\n## Environment Notes\n\nThis section is only relevant in Rails environments.\n\nThe expectation is that Loba statements are just for development or test trace statements.  Generally, it's a bad idea to leave diagnostic code in Rails production; still, it can happen. And, occasionally, it can be useful to have trace statements in production too if you have an issue that is difficult to reproduce.\n\n`Loba.ts` and `Loba.val` try to protect against timestamp or value notice requests being accidentally left in the code by checking for the Rails environment Loba is being invoked under. If in production, `Loba.ts` and `Loba.val` will normally just return immediately without attempting to render anything to help minimize any impact on production code.\n\nHowever, that behavior can be overridden by using the option `production: true` as an additional argument to output a notice even when in the production environment. Note also behavior of the `log` option, which defaults to `false` (introduced in v2.0.0). In general, enabling in production should not be done, but we're consenting adults.\n\nWARNING: this gem depends on the [binding_of_caller gem](https://rubygems.org/gems/binding_of_caller) -- use `production: true` with their warning in mind:\n\u003e **Recommended for use only in debugging situations. Do not use this in production apps.**\n\nThese considerations also have an impact on how you install the Loba gem when using `bundler`. If you only install the gem for `:development` and `:test`, then any Loba statements left in the code when it goes to production will cause an error because the statements wouldn't be recognized. That can be a good thing if you never want them left in.\n\nIf you simply install the gem for all environments, then Loba will be available in production, but you may not notice as easily if some Loba calls are unintentionally left in. Of course, if you want Loba statements to possibly work in production, then you should install the gem for all environments.\n\nThe following is the code example snippet but always logging even in Rails production environments:\n\n```ruby\nclass HelloWorld\n  def initialize\n    @x = 42\nLoba.ts log: true, production: true\n    @y = \"Charlie\"\n  end\n\n  def hello\nLoba.val :@x, log: true, production: true\n    puts \"Hello, #{@y}\" if @x == 42\nLoba.ts true\n  end\nend\nHelloWorld.new.hello\n```\n\n## Installation\n\nSee above Environment Notes if using with Rails.\n\nInstall as below to be generally available (recommended to restrict to only local use):\n\n```bash\ngem install loba\n```\n\nTo bundle, add this line to your application's Gemfile:\n\n```ruby\ngroup :development, :test do\n  gem 'loba', require: false\nend\n```\n\nor for all environments (for example, if `production: true` used):\n\n```ruby\ngem 'loba', require: false\n```\n\nAnd then execute:\n\n```bash\nbundle install\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\nTo release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for details. This gem follows semantic versioning.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at \u003chttps://github.com/rdnewman/loba\u003e. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdnewman%2Floba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdnewman%2Floba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdnewman%2Floba/lists"}