Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant Logger (NameError)

Tags:

ruby

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)
like image 249
Maxim Veksler Avatar asked Jul 01 '14 13:07

Maxim Veksler


2 Answers

You probably need to require 'logger'.

like image 184
simonwo Avatar answered Oct 16 '22 07:10

simonwo


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

like image 1
Pedro Trujillo Avatar answered Oct 16 '22 07:10

Pedro Trujillo