Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method 'types=' and 'types' for TTY::Logger::Config #3

Closed
IotaSpencer opened this issue Aug 10, 2019 · 2 comments
Closed

Comments

@IotaSpencer
Copy link

IotaSpencer commented Aug 10, 2019

Applicable Code

$logger = TTY::Logger.new(output: :console) do |cfg|
  cfg.metadata = %i[date time file]
  cfg.types = {
    success: { level: :info },
    task: { level: :info },
    err: { level: :error }
  }
  cfg.handlers = [
    [
      :console, {
        styles: {
          success: { symbol: "\u2705", label: "[#{Paint['SUCCESS', 'green']}]", color: :green, levelpad: 2 },
          err: { symbol: "\u2717", label: "[#{Paint['ERROR', 'red']}]", color: :red, levelpad: 2 },
          task: { symbol: "\u2192", label: "[#{Paint['STARTING TASK', 'orange']}]:", color: :pale, levelpad: 2 }
        }
      }
    ]
  ]
end

Traceback

Traceback (most recent call last):
       3: from /sites/make_dirs.rb:21:in `<main>'
       2: from /sites/make_dirs.rb:21:in `new'
       1: from /var/lib/gems/2.5.0/gems/tty-logger-0.1.0/lib/tty/logger.rb:44:in `initialize'
/sites/make_dirs.rb:24:in `block in <main>': undefined method `types=' for #<TTY::Logger::Config:0x000055734c1272e8> (NoMethodError)

Gem Query

root@gems:/sites# gem query -r tty-logger

*** REMOTE GEMS ***

rails-pretty-logger (0.2.6)
tty-logger (0.1.0)
@piotrmurach
Copy link
Owner

Hi, thanks for taking a look at this gem!

It's because I haven't released a new version yet changelog. I will try release shortly.

@piotrmurach
Copy link
Owner

Hi Ken,

Sorry for the late reply but I took a bit of a break from open source. However, I'm back and just released v0.2.0.

Few comments on your sample. The :output needs to be an IO object see output streams section. By default, it uses stderr.

You cannot use :success as the name as it's already defined by the library. I changed it to :succ.

All the colours are based on the pastel gem.

With these changes a fully working code looks like this:

require "pastel"

pastel = Pastel.new

logger = TTY::Logger.new do |cfg|
  cfg.metadata = %i[date time file]
  cfg.types = {
    succ: { level: :info },
    task: { level: :info },
    err: { level: :error }
  }
  cfg.handlers = [
    [
      :console, {
        styles: {
          succ: { symbol: "\u2705", label: "[#{pastel.green('SUCCESS')}]", color: :green, levelpad: 2 },
          err: { symbol: "\u2717", label: "[#{pastel.red('ERROR')}]", color: :red, levelpad: 2 },
          task: { symbol: "\u2192", label: "[#{pastel.yellow('STARTING TASK')}]:", color: :yellow, levelpad: 2 }
        }
      }
    ]
  ]
end

logger.succ "Test"
logger.task "Test"
logger.err "Test"

I hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants