# Keeping your logs from becoming an unreadable mess

DevFeed: [Keeping your logs from becoming an unreadable mess](<https://devfeed.tech/articles/keeping-your-logs-from-becoming-an-unreadable-mess-26273.md>)

Original publisher: [Read original article](<https://www.justinweiss.com/articles/keeping-your-logs-from-becoming-an-unreadable-mess/>)

Author: Justin Weiss

Published: 2015-09-08T07:23:49Z

Content type: tutorial

Language: en

Sources: [Justin Weiss](<https://devfeed.tech/sources/justin-weiss.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Logging](<https://devfeed.tech/topics/logging.md>), [log management](<https://devfeed.tech/topics/log-management.md>), [debug](<https://devfeed.tech/topics/debug.md>), [GitHub API](<https://devfeed.tech/topics/github-api.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [debug](<https://devfeed.tech/tags/debug.md>), [gateway](<https://devfeed.tech/tags/gateway.md>), [github](<https://devfeed.tech/tags/github.md>), [json](<https://devfeed.tech/tags/json.md>), [logging](<https://devfeed.tech/tags/logging.md>), [logs](<https://devfeed.tech/tags/logs.md>), [rails](<https://devfeed.tech/tags/rails.md>)

## AI overview

This tutorial explains how to use Rails TaggedLogging to make log messages easier to categorize and filter. It shows how tagged logs can clarify request activity, calls to other APIs, background jobs, and logged-in user activity, helping developers trace complex paths and investigate bugs.

## Source excerpt

When you run into a strange, seemingly unsolvable bug, improving your logging can be the best step you can take. Great logging is the easiest way to detect and fix entire classes of bugs. When you log enough information, you can see how your data changes during a request. You can track the calls you make to other services, and investigate the response. In fact, when debuggers failed, logging helped me fix the toughest bug I've ever run into. But log too much, and your log files will quickly turn into a jumble of unreadable, unhelpful messages. How can you slice just the information you care about out of that pile of data? Can you print messages in a way that's easy to filter later? Marking your log messages Rails includes TaggedLogging, which can help you quickly categorize related log messages. When you tag a logger, you'll get a marker at the beginning of your message. So instead of: Finding people... Person Load (0.3ms) SELECT "people".* FROM "people" Found 0 people! You could tag the Rails logger: logger.tagged("People") do logger.debug "Finding people..." @people = Person.all logger.debug "Found #{@people.length} people!" end And you'd see something like this: [People] Finding people... [People] Person Load (0.3ms) SELECT "people".* FROM "people" [People] Found 0 people! Now, log messages that care about different things can look different. Some tagged logger examples As you log more often, and log more complicated things, you'll naturally notice areas where those tags will make your messages clearer. But there are a few places I've found tagged logging particularly helpful. I'll usually tag those right away. You can log requests you make to other APIs: logger.tagged("GitHub API") do uri = URI("https://api.github.com/repos/rails/rails/tags") logger.info { "Fetching #{uri}" } tags = JSON.parse(Net::HTTP.get(uri)) logger.info { "First tag: #{tags.first["name"]}" } end [GitHub API] Fetching https://api.github.com/repos/rails/rails/tags [GitHub API] First tag: v4.2