Logger not working / improve error messages
Hello, I spent a lot of time today trying to track down the cause of an Mp3InfoEOFError. I figured this was due to a corrupted audio file, however I was working with a large number of files and needed to figure out which one was causing the error. Enabling --verbose and --trace didn't provide any useful diagnostics so I decided to try modifying the gem.
I see there is some sort of custom Logging class in use inside lib/dropcaster. However the only log messages I see actually getting logged are those coming from bin/dropcaster. All the other files containing logger.error etc. appear to just go into the void. I also tried adding print and puts inside these files and also did not see anything get logged to console.
I was evenutally able to track it down by adding a rescue block and raising a custom error like so (inside item.rb) which gets caught and logged by bin/dropcaster:
def initialize(file_path, options=nil)
logger.info("at file path " + file_path.to_s) # This doesn't work
begin
Mp3Info.open(file_path) { |mp3info|
@file_path = Pathname.new(File.expand_path(file_path)).relative_path_from(Pathname.new(Dir.pwd)).cleanpath
@tag = mp3info.tag
@tag2 = mp3info.tag2
@duration = mp3info.length
if @tag2['ULT']
@lyrics = {}
@tag2['ULT'].split(/\x00/).drop(1).each_slice(2) { |k, v| @lyrics[k] = v }
end
}
rescue Mp3InfoEOFError => error
logger.error("Mp3InfoEOFError " + error.to_s) # This doesn't work
raise "Mp3InfoEOFError at " + file_path.to_s
end
This code was pretty rough so I didn't want to open a PR yet but I wanted to see why the logs might be getting swallowed first, as that seems like an easier solution to provide more useful diagnostics to the end user.
OS: macOS 10.13.6 Ruby Version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17] (installed via rbenv) dropcaster gem version: 1.0.0
Thanks for the issue. Could you contribute a sample MP3 file that reproduces this error?
In general, PRs are always welcome, even if they are rough. That way we can work on improving it before merging it into master.
Thanks for the response. I'm not sure how to fix this as I'm not so good with Ruby and I don't understand how your custom Logger is supposed to work in the first place. I think if you call logger.error from anywhere within lib/dropcaster you will see the log does not show up in terminal. But if you are unable to get this working I can put together a more fleshed-out repro case.
Please re-open if the problem still persists.