• Narrow screen resolution
  • Wide screen resolution
  • Auto width resolution
  • Increase font size
  • Decrease font size
  • Default font size
  • default color
  • red color
  • green color

Got Good Credit ?

Saturday
Feb 11th
FireBoard
Welcome, Guest
Please Login or Register.    Lost Password?
ruby use system variable Is it ellegant to use a global variable to store a Logger object? (0 viewing) 
Go to bottom Post Reply Favoured: 0
TOPIC: ruby use system variable Is it ellegant to use a global variable to store a Logger object?
#43721
ruby use system variable Is it ellegant to use a global variable to store a Logger object?  
Hi, I use Logger class in a programm and since I need to log in lot of different places (into classes, into methods...) I use a global variable in this way:   $log = Logger.new   $log.debug ... so I can use $log anywhere in the code. Is it ellegant and the Ruby way ? The other possibility I see is creating a class that stores the logger instance into a @@class_variable (@@logger) and call class method anywhere in the code:   class MyLogger     @@logger = Logger.new     def self.debug(x)       @@logger.debug(x)     end     ...   end   MyLogger.debug ... Which is a more ellegant way? is there other option? Thanks for any advice I could receive from you.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#43722
Suraj Kurapati (Visitor)
Click here to see the profile of this user
Birthdate:
ruby use system variable Is it ellegant to use a global variable to store a Logger object?  
  $log = Logger.new   $log.debug ... The other possibility I see is   class MyLogger     @@logger = Logger.new     def self.debug(x)       @@logger.debug(x)     end   end   MyLogger.debug ... is there other option? You could add a debug() method to the Kernel module: module Kernel   @@logger = Logger.new   def debug message     @@logger.debug message   end end Then you could call it from anywhere in your code.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#43723
ruby use system variable Is it ellegant to use a global variable to store a Logger object?  
  $log = Logger.new   $log.debug ... The other possibility I see is   class MyLogger     @@logger = Logger.new     def self.debug(x)       @@logger.debug(x)     end   end   MyLogger.debug ... is there other option? You could add a debug() method to the Kernel module: module Kernel   @@logger = Logger.new   def debug message     @@logger.debug message   end end Then you could call it from anywhere in your code. Oh, interesting. Anyway let me a question: How ellegant is using Kernel module? Imagine you are programming a _frame_work that others can use in their programms. Isn't dangerous to extend/modify Kernel module since it will be shared by *all* the code? Thanks a lot.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#43724
Suraj Kurapati (Visitor)
Click here to see the profile of this user
Birthdate:
ruby use system variable Is it ellegant to use a global variable to store a Logger object?  
Imagine you are programming a _frame_work that others can use in their programms. Isn't dangerous to extend/modify Kernel module since it will be shared by *all* the code? True.  In that case, I would put the debug() method or the LOG _object_ in the top-level module of my library/_frame_work: # Using a debug() method module FooBar   module Logging     @@logger = Logger.new     def debug msg       @@logger.debug msg     end   end   class FooBar::Baz     include Logging  # <== NOTE this!     def oh_no       debug oh no!     end   end end # Using a LOG _object_ module FooBar   LOG = Logger.new   class FooBar::Baz     def oh_no       LOG.debug oh no!     end   end end
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#43725
ruby use system variable Is it ellegant to use a global variable to store a Logger object?  
# Using a LOG _object_ module FooBar   LOG = Logger.new   class FooBar::Baz     def oh_no       LOG.debug oh no!     end   end end Ok, in this case you use a constant (LOG). This is the same I do now but I use a global variable ($log). Is more ellegant using a constant? Thanks a lot.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#43726
Suraj Kurapati (Visitor)
Click here to see the profile of this user
Birthdate:
ruby use system variable Is it ellegant to use a global variable to store a Logger object?  
# Using a LOG _object_ module FooBar   LOG = Logger.new   class FooBar::Baz     def oh_no       LOG.debug oh no!     end   end end Ok, in this case you use a constant (LOG). This is the same I do now but I use a global variable ($log). Is more ellegant using a constant? Yes, in my opinion.  A constant is constrained to the walls of your library's top-level module, whereas a global variable is not. Therefore, unless someone was modifying your library, they would not be able to access your constant.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop
 

Short News

Cache Directory Unwriteable


The record number of countries will be penalized for an excessive deficit

Tackling the crisis in the States absorbs a quantity of Furniture accessories directory Polish builders website marketing money that the situation in the budgets of countries is becoming increasingly tense. Sometimes you can even the impression that the authorities of the country completely lost control of the state of equilibrium in the public hand. Excessive deficit begins to consume more and more countries from the EU, the EC decided to take the steps to run against some of the excessive Business news spring 2012 fashion Villa For Sale In Mirdif deficit procedure.

Global economic crisis is increasingly beginning to impress their niechlubne influenced the condition of the public finance sector in the EU. The result is a deepening gap between the level of income and expenditure budgets of the member countries, and consequently further harper beckham BLC4u international phone cards increase their current debt.

Today the governments of many EU countries are becoming major problems in order to maintain the budget deficit in the toes and thus does not exceed the permissible limit of 3 percent. GDP, which was provided for in the Treaty of Fönsterputs Fertighäuser Englisch online lernen Maastricht. Unfortunately, it probably will be few of them. Do not respect the EU standards in this matter at the initial stage, may threaten the imposition of financial sanctions on the country, and then complete with money coming mostly from EU funds. NB the occurrence of excessive deficits in the Member States of the Community also raises issues associated with maintaining the overall level of its stability, and thus the credibility and in the used vans BLC4u remortgage help international arena.


stare zdjêcia
Stare, Zdjêcia
www.fotokolej.pl
Dragon Ball
Dragon Ball
www.kreskowka.pl
kredyty
kredyty
moj-bank.com
sportowy
sportowy
www.sportowy.glade.…
hologramy

www.vera.com.pl
Pozycjonowanie Kidprotect Mam Marzenie Pajacyk Fundacja Hobbit Krwinka