I have a gem which I wrote and I use it inside my rails application.
I want to write to rails logger from my gem but obviously the standard rails logger doesn’t exist there.
What is the right way to achieve what I want to do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
While you should be able to use
Rails.loggeryou might want to consider making the logger that your gem uses configurable, i.e. allow users to setMyGem.loggerto whatever logger they want.You can default it to something that just writes to stdout, in a rails app you can set
MyGem.logger = Rails.loggerin an initialiser. People who are using your gem outside of rails can do so too.