undefined method 'types=' and 'types' for TTY::Logger::Config
IotaSpencer opened this issue · 2 comments
IotaSpencer commented
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 commented
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 commented
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!