简体   繁体   中英

uninitialized constant Logger (NameError)

I'm trying to define a custom logger for Logger class and getting uninitialized constant Logger.

The same code worked up to a few days ago, any idea what could make it break ? https://github.com/sugarso/ScrapingTheApple/blob/master/JustScrape.rb#L48

Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ ruby JustScrape.rb
JustScrape.rb:48:in `<main>’: uninitialized constant Logger (NameError)

您可能需要require 'logger'

You forgot initialize the logger class at the top of your program/class with :

require 'logger'

ex:

require 'logger'
logger = Logger.new('MyLog.log')
logger.debug("Program start");
logger.info("Hello Word!")

This will show in your MyLog.log file something like:

# Logfile created on 2017-05-11 11:03:20 -0400 by logger.rb/41756
D, [2017-05-11T11:03:20.802629 #57077] DEBUG -- : Program start
I, [2017-05-11T11:03:20.802689 #57077]  INFO -- : Hello Word!

More information here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM