Skip to Content Treasure Data Logo Treasure Data Logo
  • Product
    • Agentic Experience Platform
      • Why Treasure AI? You set the strategy and guardrails. AI executes, 24/7.
      • Agentic Experience Platform
      • Pricing
      • Trust & Security
    • AI (Artificial Intelligence)
      • Treasure AI Studio 10x campaigns. 10x conversions. One workspace.
      • Treasure Code (CLI) Reduce the operational burden of CDP by up to 90%.
      • AI Agent Hub
    • Activation
      • AI Suites Activate the right experience, in the right channel, every time.
      • Engagement Suite
      • Personalization Suite
      • Creative Suite
      • Paid Media Suite
      • Service Suite
    • Context
      • Customer Data Platform Manage every context around your customers.
      • Complete CDP
      • Composable CDP
      • Identity Resolution
      • Integrations
  • Solutions
    • Industries
      • Automotive
      • CPG
      • Entertainment & Media
      • Financial Services
      • Healthcare
      • Retail
      • Technology
      • Travel & Hospitality
    • Channels
      • Email Marketing
      • Mobile App Marketing
      • SMS Marketing
      • LINE Marketing
    • CDWs & AI Tools
      • Snowflake
      • Databricks
      • BigQuery
      • Claude Code
      • OpenAI Codex
      • VS Code (Github Copilot)
      • Cursor
  • Customers
  • Resources
    • Explore
      • Resource Library
      • Case Studies
      • Blog
      • Documentation
      • Trust Center
      • Training
      • Events
      • Webinars
    • Get Started
      • Demo Experience Treasure Data with an expert-led walkthrough.
      • Trade-Up Program Replace your CEP, CDP, or ESP. Save big with special incentives.
  • Company
    • Company
      • About Us
      • Careers
      • Partners
      • News
      • Contact Us
      • Terms
Login
Get a demo

Treasure AI Named Leader in New IDC MarketScape

  • Menu Item 1
    • Sub-menu Item 1
      • Another Item
    • Sub-menu Item 2
  • Menu Item 2
    • Yet Another Item
  • Menu Item 3
  • Menu Item 4
Blog
    • CDP
    • Customer Data Strategy
    • AI & Machine Learning
    • CDP Use Cases
    • Marketing
    • Treasure Data CDP
    • Data Privacy & Security
    • Partners
    • AI & Marketing
    • Company News
    • Data Strategy
    • Privacy & Security
    • Customer Service
April 26, 2012

Log Everything as JSON. Make Your Life Easier

Ron Zvagelsky Ron Zvagelsky
  • Treasure Data CDP

The Story of an Engineer.

Here is an anecdote. I am sure some of you have had a similar experience.

  • Alex, an engineer, logs all kinds of events. Since he is the primary consumer of the log, the format is optimized for human-readability. One canonical example is Apache logs:10.0.1.22 - - [15/Oct/2010:11:46:46 -0700] "GET /favicon.ico HTTP/1.1" 404... 10.0.1.22 - - [15/Oct/2010:11:46:58 -0700] "GET / HTTP/1.1" 200...This looks great. Time stamp, URL, HTTP status code...each line gives Alex a lot of information to work with if the service is having issues.
  • Bob, a business analyst, asks Alex for the number of daily unique users. Alex writes a parser for the Apache log and crontabs the script. He also builds a little Web interface so that his colleague can query the parsed data on his own. Bob finds the interface super useful.
  • Bob comes back a few weeks later and complains that the web interface is broken. Alex scratches his head and takes a look at the logs, only to realize that someone added an extra field in each line, breaking his custom parser. He pushes the change and tells Bob that everything is okay again. Instead of writing a new feature, Alex has to go back and has to fill back the missing data.
  • Every 3 weeks or so, repeat Step 3.

What is Wrong With This?

The takeaway lesson of the above story is twofold:  (1) logs are not just for humans to read and (2) logs change. (1) Logs are not just for humans. As  Paul Querna points out, the primary consumer of logs are shifting from humans to computers. This means log formats should have a well-defined structure that can be parsed easily and robustly. (2) Logs change. If the logs never changed, writing a custom parser might not be too terrible. The engineer would write it once and be done. But in reality, logs change. Every time you add a feature, you start logging more data, and as you add more data, the printf-style format inevitably changes. This implies that the custom parser has to be updated constantly, consuming valuable development time.

Enter JSON!

Here is a suggestion: Start logging your data as JSON. JSON has a couple of advantages over other "structures".

  • Widely adopted. Most engineers know what JSON is, and there is a JSON library for every language imaginable. This means there is little overhead to parse logs.
  • Readable. Readability counts because engineers have to jump in and read the logs if there is a problem. JSON is text-based (as opposed to binary-based) and its format is a subset of JavaScript object literal (which most engineers are familiar with). In fact, properly formatted JSON is easier to read than logs formatted in ad hoc ways.

An Example of JSON-based Logging: Fluentd

We've already  talked about Fluentd in this blog, so I won't bother you with the details. It's a logging daemon that can talk to a variety of services (ex:  MongoDB,  Scribe, etc.) One of the key features of Fluentd is that  everything is logged as JSON. Here is a little code snippet that logs data to Fluentd from Ruby.

require 'fluent-logger'
 # some code in between
 log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port=>24224)
 log.post('myapp.access', {"user-agent" => user_agent})
 
Now, suppose you wanted to start logging the referrer URL in addition to user agent. You just need to update the Ruby hash that corresponds to JSON.
require 'fluent-logger'
 # some code in between
 log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port=>24224)
 log.post('myapp.access', {"user-agent" => user_agent, "referrer" => referrer_url}) # Added a field!
 
That's the only change you need to make. All the existing scripts work as before, since all we did was adding a new field to the existing JSON. In contrast, imagine you were logging the same data in a printf-inspired format. Your code initially looks like this:
log = CustomLogger.new
 #some code in between
 log.post("web.access", "user-agent: #{user_agent} blah blah")
 
When you decide to log the referrer URL, you update it to:
log = CustomLogger.new
 #some code in between
 log.post("web.access", "user-agent: #{user_agent} blah blah referrer: #{referrer_url}")
 

 

Now, most likely your old parser is broken, and you have to go and update your regex and whatnot. We are biased towards Fluentd because we wrote it ourselves. But regardless of what software/framework you choose for logging, you should start logging everything as JSON right away.

Topics Covered

  • Treasure Data CDP

Share this story:


Subscribe
Get Treasure Data blogs, news, use cases, and platform capabilities:

Thank you for subscribing to our blog!

Recent Posts

AI & Machine Learning 6 min read 2026.Jul.06
Treasure AI Recognized as a Leader in the IDC MarketScape Worldwide AI-Enabled Customer Data Platforms for B2C Users 2026
When Your Data Platform Wants to Become a CDP
5 min read 2026.Jun.15
When Your Data Platform Wants to Become a CDP | Treasure AI
19 min read 2026.May.19
Data Activation: The Complete Enterprise Guide [2026]
Treasure Data Logo Symbol

+1 866.899.5386 (US)
+1 650.772.4500 (Non-US)

  • Product
    • Agentic Experience Platform
      • Why Now?
      • Agentic Experience Platform
      • Pricing
      • Trust & Security
    • AI (Artificial Intelligence) Layer
      • Treasure AI Studio
      • Treasure Code
      • Agent Hub
    • Activation
      • Treasure AI Suites
      • Engagement AI Suite
      • Creative AI Suite
      • Personalization AI Suite
      • Paid Media AI Suite
      • Service AI Suite
    • Context
      • Customer Data Platform
      • Complete CDP
      • Composable CDP
      • Identity Resolution
      • Integrations
  • Solutions
    • Industries
      • Automotive
      • CPG
      • Entertainment & Media
      • Financial Services
      • Healthcare
      • Retail
      • Technology
      • Travel & Hospitality
    • Channels
      • Email Marketing
      • Mobile App Marketing
      • SMS Marketing
      • LINE Marketing
    • CDWs & AI Tools
      • Snowflake
      • Databricks
      • BigQuery
      • Claude Code
      • OpenAI Codex
      • VS Code (Github Copilot)
      • Cursor
  • Resources
    • Explore
      • Resource Library
      • Case Studies
      • Blog
      • Pricing
      • Documentation
      • Training
      • Events
      • Webinars
    • Get Started
      • Demo
      • AI Workshop
      • Fast Proof of Concept
      • RFP Template
      • Trade-Up Program
      • Value Calculator
  • Company
    • Company
      • About Us
      • Customers
      • Partners
      • Careers
      • News
      • Contact Us
      • Terms
  • Get a demo
  • Terms & Conditions
  • Privacy Statement
  • Cookie Policy
  • Privacy Hub
  • Trademarks
  • Modern Slavery Statement
  • Your Privacy Choices
©2026 Treasure AI All rights reserved.