dotenv icon indicating copy to clipboard operation
dotenv copied to clipboard

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

Open ndbroadbent opened this issue 4 months ago • 1 comments

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.

ndbroadbent avatar Sep 08 '25 10:09 ndbroadbent

Hi @ndbroadbent. The current behavior of only logging to the file and not to stdout is not intentional. If there's a better time to replay the logs then I would be up for changing the behavior.

bkeepers avatar Sep 08 '25 12:09 bkeepers