Skip to content

Replace default logging with semantic logging - #363

Merged
matt-bernhardt merged 4 commits into
mainfrom
tco-220
Sep 11, 2026
Merged

Replace default logging with semantic logging#363
matt-bernhardt merged 4 commits into
mainfrom
tco-220

Conversation

@matt-bernhardt

@matt-bernhardt matt-bernhardt commented Sep 9, 2026

Copy link
Copy Markdown
Member

This replaces the default logging configuration with semantic logging, in anticipation of integrating with a different cloud logging provider.

We define the application name as a blanket attribute, and then use different log targets for development and production environments. In order to aid local development, we also turn to the amazing_print gem for better formatting.

On Heroku, we use the JSON formatter that will prepare log content in a way that's sympathetic to cloud logging providers.

Developer

Ticket(s)

https://mitlibraries.atlassian.net/browse/TCO-220

Accessibility

  • ANDI or Wave has been run in accordance to our guide and
    all issues introduced by these changes have been resolved or opened
    as new issues (link to those issues in the Pull Request details above)
  • There are no accessibility implications to this change

Documentation

  • Project documentation has been updated, and yard output previewed
  • No documentation changes are needed

ENV

  • All new ENV is documented in README.
  • All new ENV has been added to Heroku Pipeline, Staging and Prod.
  • ENV has not changed.

Stakeholders

  • Stakeholder approval has been confirmed
  • Stakeholder approval is not needed

Dependencies and migrations

YES dependencies are updated

NO migrations are included

Reviewer

Code

  • I have confirmed that the code works as intended.
  • Any CodeClimate issues have been fixed or confirmed as
    added technical debt.

Documentation

  • The commit message is clear and follows our guidelines
    (not just this pull request message).
  • The documentation has been updated or is unnecessary.
  • New dependencies are appropriate or there were no changes.

Testing

  • There are appropriate tests covering any new functionality.
  • No additional test coverage is required.

This defines different appenders for dev and prod tiers.

The prod tier is taken from the gem docs, the dev tier is a bit
of a judgement call on my part.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The environment configs currently contain conflicting logger setups (semantic logger appenders plus explicit config.logger overrides) that can override or duplicate logging behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Introduces Semantic Logger–based structured logging by adding rails_semantic_logger, configuring environment-specific appenders (JSON to stdout in production, color/file output in development), and setting a consistent SemanticLogger.application name.

Changes:

  • Add rails_semantic_logger (and supporting gems) to the bundle.
  • Configure semantic logger appenders in production.rb and development.rb.
  • Set SemanticLogger.application via RAILS_APP_NAME (with a default) in config/application.rb.
File summaries
File Description
Gemfile.lock Adds locked dependencies for semantic logging and pretty-printing.
Gemfile Adds rails_semantic_logger and amazing_print dependencies.
config/environments/production.rb Adds production semantic logger appender configuration (JSON).
config/environments/development.rb Adds development semantic logger appender configuration (color + file + server).
config/application.rb Sets global SemanticLogger.application name via ENV/default.
Review details
  • Files reviewed: 4/5 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread config/environments/development.rb Outdated

# Log configuration for rails_semantic_logger
config.rails_semantic_logger.appenders do |appenders|
appenders.add(file_name: "log/#{Rails.env}.log", formatter: :color)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recommend we log to a file even in development.

Timdex has this commented out: https://github.com/MITLibraries/timdex/blob/main/config/environments/development.rb#L68-L71

Timdex-UI does as well:
https://github.com/MITLibraries/timdex-ui/blob/main/config/environments/development.rb#L80-L83

They both use a stdout line as the only dev mode and it's pretty useful output. I haven't checked what the format of this is though so I'm not specifically saying to to what the other apps do other than use stdout instead of the log file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries - for the times when I want to parse a larger number of log lines in an editor, I can grab them from the terminal output.

Comment thread config/environments/development.rb
Comment thread config/environments/production.rb
Comment thread Gemfile
@mitlib
mitlib temporarily deployed to tacos-api-pipeline-pr-363 September 9, 2026 20:18 Inactive
@matt-bernhardt matt-bernhardt changed the title First attempt at semantic logging Replace default logging with semantic logging Sep 9, 2026
Comment thread config/application.rb Outdated
# This application leverages SemanticLogger for more useful logging and
# insights. The details of that implementation vary by environment, but
# certain configuration is the same everywhere.
SemanticLogger.application = ENV.fetch("RAILS_APP_NAME", "tacos")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. While I agree this is fine, I'm not confident any tier other than prod really needs this. The risk of it being here is that it separates the configuration across multiple config files which might make it harder to keep track of. I don't see the value of setting this in dev or test which are the only env other than production focus.

@JPrevost JPrevost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not log dev to a file. We'll never remember to delete it and inevitably be confused when we don't have hard drive space over time :)

- Remove logging to a file in dev environments
- Move the application name to the prod environment specifically
@mitlib
mitlib temporarily deployed to tacos-api-pipeline-pr-363 September 10, 2026 14:35 Inactive
Comment thread config/environments/development.rb Outdated
# Log configuration for rails_semantic_logger
config.rails_semantic_logger.appenders do |appenders|
appenders.add_server(
formatter: {color: {ap: {multiline: true}}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about how to handle multiline true vs false.

timdex-ui and api do not set this to true. If we have a different preference on the team for how this works across apps, we should likely make this a consistently configurable value via ENV that defaults to the majority preference on the team. I'll bring this up in Slack before we proceed with this and other apps to ensure we are normalizing where appropriate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-bernhardt Team agreement in Slack was to make this value configurable. See Slack for convo about the default value and suggested implementation pattern.

@mitlib
mitlib temporarily deployed to tacos-api-pipeline-pr-363 September 10, 2026 21:02 Inactive
@matt-bernhardt
matt-bernhardt merged commit 949d805 into main Sep 11, 2026
7 checks passed
@matt-bernhardt
matt-bernhardt deleted the tco-220 branch September 11, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants