Rails: Log stuff to rails app logs from any ruby class -


I want to be able to log in to my Rails app logs from Ruby Class.

I was hoping to do a class with logger.info "some stuff" in my_app / app / myClass.rb , but it It is not defined when I use logger in my controllers and elsewhere then it works

I'm brand new to Rail / Ruby, and I'm assuming it That is because logger category myClass.rb , but it is automatically included in all controllers, models, etc.

How can I include the logger class in an arbitrary Ruby class, or else I can login to my Rail App from a Ruby Class?

"Post-Text "Itemprop =" text ">

If you want to create your own logger:

  class MyClass def initialize @app_logger = Logger.new (" # {Rails.root} / log /app.log ") End DEF Other Method @ app_logger.info (" Anything here ") End / <>    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -