Skip to content

Question about logging in development - Is it intentional to only save logs in log/development.log and not stdout? #537

Description

@ndbroadbent

I'm working on a new structured logging gem (https://github.com/DocSpring/logstruct) and I've set up structured logging for dotenv-rails. I was just a bit confused about how it's supposed to work and if the current behavior is intentional or not.

In a default brand new Rails app, I only see dotenv messages in log/development.log, not in the terminal when running rails server.

From what I can tell, this happens because dotenv initializes very early in the boot process, before Rails has finished setting up its logger. Rails attaches the ActiveSupport::Logger.broadcast($stdout) during the :initialize_logger step, but dotenv logs its “Loaded .env.*” and “Set …” messages just before that. By the time Rails has wired STDOUT into Rails.logger, dotenv has already replayed its buffered logs into the file logger only.

In my own Rails app, I've changed logging so that everything goes to stdout immediately and I don't even have a development.log file, so I hadn't come across this issue before. I was just curious to know if the behavior is intentional and if I should try to preserve this when I set up the structured logging integration in LogStruct.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions