# Problems with LOG

**URL:** <https://www.ruby-forum.com/t/problems-with-log/186320>\
**Category:** Rails\
**Created:** [April 4, 2010, 8:07pm UTC](https://www.ruby-forum.com/t/problems-with-log/186320 "2010-04-04T20:07:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 4, 2010, 8:07pm UTC](https://www.ruby-forum.com/t/problems-with-log/186320/1 "2010-04-04T20:07:45Z")

</div>

It’s probably a begginers question…but, in a controller I have:

```
logger = Logger.new(STDOUT)
logger.info "Testing logger at controller"

```

When running my app in my machine, I can see this log in  
log/development.log file.

When running in production, this log is not printed. Not even with  
“puts” …

Info is the default level for Logger when running in  
production…so…Why can’t I see my logs in production environmnent ?  
Any help ?

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 4, 2010, 8:29pm UTC](https://www.ruby-forum.com/t/problems-with-log/186320/2 "2010-04-04T20:29:36Z")

</div>

On Apr 4, 7:07 pm, Anderson L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s probably a begginers question…but, in a controller I have:
> 
> ```
> logger = Logger.new(STDOUT)
> logger.info "Testing logger at controller"
> 
> ```
> 
> When running my app in my machine, I can see this log in  
> log/development.log file.
> 
> When running in production, this log is not printed. Not even with  
> “puts” …

I don’t think STDOUT is connected to anything in particular in  
production (since typically the process will have detached from the  
terminal that launched it)  
If you just want to write to the standard log file why do you need to  
create your own logger?

Fred

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 5, 2010, 3:21am UTC](https://www.ruby-forum.com/t/problems-with-log/186320/3 "2010-04-05T03:21:45Z")

</div>

What’s the best way to initialize logger and where to do it ?

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [April 5, 2010, 3:26am UTC](https://www.ruby-forum.com/t/problems-with-log/186320/4 "2010-04-05T03:26:26Z")

</div>

well…

To log a message from either a controller or a model, access the Rails  
logger instance with the logger method:

class HomeController \< ActionController::Base  
def index  
logger.info ‘informational message’  
end  
end

From outside a controller or model, you can pass the logger instance or  
access it with the constant RAILS\_DEFAULT\_LOGGER. Since Rails 2.1, you  
can also access it with the shortcut Rails.logger.

In an initializer file, Rails.logger is the best way to log ?

thanks
