Skip to content

Allow logging Operation#wtf?Β #45

@phillipoertel

Description

@phillipoertel

Hey there,

our developers love #wtf? and leave it in even after feature development is complete, to reproduce and debug on staging/prod what was going on, in case something fails (it happens ;-D).

Problem is, the #wtf output messes up the output of tests, particularly rspec when run in --format documentation mode, and the #wtf output can't be turned off easily at the moment.

So my request is:

  • allow configuring where the output of #wtf? goes -- to STDOUT by default (backwards compatibility), to a logger (i.e. allow assigning a logger that the wtf output gets sent to), or somewhere else (silencing it by setting the config to nil/false)
  • I think the log level should be debug or at most info
  • (optional) if running in Rails context, use it's logger by default

One thing I'm not so sure about is how to preserve the colorized, "ASCII-art" output of wtf in a log message. As is, will be quite hard to read and piece together if sent to a logger. In the simplest case, just make sure all of output ends up in a single log message, including the ASCII colorization codes and newlines. Then it will be fairly easy to copy out and restore. Serializing such a tree structure to a (JSON) string may be another option; but that's possible overkill and will likely be harder to read anyways. Maybe you additional ideas. What wouldn't work well is to send each line of output as a separate message, it will be hard to piece together again.

I've attached a screenshot of a typical #wtf? output for reference:

Bildschirmfoto 2024-07-13 um 11 17 28

And here's the monkeypatch we currently use to silence #wtf?, as it may be helpful to others. It works in the context of a Rails application using the dotenv gem for configuration.

In RAILS_ROOT/.env:

[...]
# turn on to suppress trailblazer's wtf? output (in specs, for example)
SILENCE_TRAILBLAZER_WTF=true

In RAILS_ROOT/config/initializers/trailblazer.rb

# monkeypatch to silence the trailblazer wtf? output
module Trailblazer::Developer
  module Wtf
    module_function

    def puts(string)
      (ENV["SILENCE_TRAILBLAZER_WTF"] == "true") ? nil : super
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions