O'Reilly logo

Data Visualization with D3 and AngularJS by Christoph Körner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing log files to JavaScript objects

Once we load the string of log entries, we need to parse these entries to an array of data points in order to display them. We want to parse the plain text log file to an array of JavaScript objects.

In this section, I will show you a convenient way to mix all techniques and to retrieve the best of both worlds. We will implement a preprocessing service component. This uses regular expressions to split the text into an array and D3.js to parse time strings to dates.

Parsing log files step by step

Let's look at the structure of the log files again:

66.249.64.121 - - [22/Nov/2014:01:56:00 +0100] "GET /robots.txt HTTP/1.1" 302 507 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 66.249.64.129 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required