DEV Community

Jeff Dwyer
Jeff Dwyer

Posted on

Tagged Logging vs Structured Logging

Understanding Tagged vs. Structured Logging

What's Tagged Logging?

Tagged logging allows you to prepend tags to your log messages. For instance, using ActiveSupport::TaggedLogging, you can tag logs with "Auth API" or user IDs.

class Permissions
  def get(user)
    logger.tagged("Auth API") do
      uri = URI("{user}") { "Fetching #{uri}" }
      permissions = Permissions.parse(Net::HTTP.get(uri)) { "Got permissions #{permissions.to_s}" }

# Log Output
#[Auth API] Fetching
#[Auth API] Got permissions admin, writer, reader
Enter fullscreen mode Exit fullscreen mode


  • Enhances log readability.
  • Avoids repetition by tagging once for multiple log lines.


  • Not machine-friendly. While the text version looks good, the JSON format can be confusing, especially when searching for specific tags.

Structured Logging: A Better Alternative?

Structured logging provides a more organized way to log messages. Instead of tagging, you structure your logs with key-value pairs.

Example: "hello", user: "1", team: "The best team"
Enter fullscreen mode Exit fullscreen mode


Text Log:
INFO hello user=1, team=The Best Team

{severity: INFO, message: "hello", user: 1, team: "The Best Team"}
Enter fullscreen mode Exit fullscreen mode

This approach is more machine-readable and fits better with modern log aggregators.

Libraries Supporting Structured Logging:

Note: Lograge offers structured logs for Rails requests but lacks custom structuring.

Why I Wrote This

I'm building a dynamic log library and wanted to understand the best approaches to structured and tagged logging.

In Summary:

  • Tagged logging is user-friendly but not machine-friendly.
  • Structured logging offers a more organized and machine-readable approach.
  • Tagged logging does have nice nesting behavior, though you can achieve that with the semantic logger gem as well.

Top comments (0)