I connect to a rails console using:
bundle exec rails c
I use enter this option in an attempt to disable ANSI colours:
irb(main):005:0> ActiveSupport::LogSubscriber.colorize_logging = false
=> false
I still see colours when I look at command outputs.
I use enter this option in an attempt to disable ANSI colours:
irb(main):006:0> IRB.conf[:USE_COLORIZE] = false
=> false
I still see colours when I look at command outputs.
I don’t have permission to change any configuration files or install any Gems.
Full Background
I just want to run some commands to look at data objects via a script and capture the output. I don’t want my file to have ANSI colour codes. I am actually doing this from my local mac using kubectl to connect to a pod where rails is running:
kubectl exec my-cool-pod-name -n my-cool-namespace-name -it -- bash -c "bundle exec rails c<<ENDRAILS
ActiveSupport::LogSubscriber.colorize_logging = false
myStuff = MyPkg::MyStuff.friendly.find("dog1")
myStuff.goodStuff
ENDRAILS
" > railsConsole.out
A work around seems to be to use the the y or j format specifiers to generate yaml or json respectively like this, but I don’t really like these formats for these objects:
y myStuff.goodStuff
j myStuff.goodStuff.inspect
I also considered removing the ANSI colour codes from out redirection output file railsConsole.out after it has been generated, but that seems messy and unreliable from looking at posts on that technique.
Rails is version 7.0.4
irb(main):007:0> Rails.version
=> "7.0.4"
>Solution :
Hmm, the IRB.conf[:USE_COLORIZE] = false should work (whether in the console, or in your ~/.irbrc). There’s a CLI option for this too which you could trigger with: rails c -- --nocolorize. But I’m not sure that’ll work if the IRB.conf doesn’t work. 🤷