---
title: "Rails 5 Sending STDOUT via environment variable"
description:
  "Rails 5 has introduced an environment variable, with the help of which logs
  can now be directed to STDOUT in production environment."
canonical_url: "https://www.bigbinary.com/blog/rails-5-allows-to-send-log-to-stdout-via-environment-variable"
markdown_url: "https://www.bigbinary.com/blog/rails-5-allows-to-send-log-to-stdout-via-environment-variable.md"
---

# Rails 5 Sending STDOUT via environment variable

Rails 5 has introduced an environment variable, with the help of which logs can
now be directed to STDOUT in production environment.

- Author: Mohit Natoo
- Published: April 12, 2016
- Categories: Rails 5, Rails

By default, Rails creates `log` directory in a file that is named after the
environment in which the application is running. So in production environment,
logs are by default directed to `production.log` file.

We will have to define custom loggers if these logs are to be directed to
another file or to standard output. Presence of such custom logic is what
enables Rails to direct logs to `STDOUT` along with `development.log` file in
development environment.

Rails 5, however,
[supports logging to STDOUT](https://github.com/rails/rails/pull/23734) in
production environment through introduction of new environment variable
`RAILS_LOG_TO_STDOUT`.

In a brand new Rails app, we can see the following snippet in `production.rb`
file.

```ruby
if ENV["RAILS_LOG_TO_STDOUT"].present?
  config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
end
```

By setting `RAILS_LOG_TO_STDOUT` to any value we should have the production logs
directed to `STDOUT`.

We can see in the snippet above `config.logger` is overwritten. Therefore now
the logs will not be directed to `production.log` file.

To opt out of this and revert to the original functionality, we can either
assign a blank value to this environment constant or remove
`RAILS_LOG_TO_STDOUT` from the list of environment constants.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-allows-to-send-log-to-stdout-via-environment-variable)
