parent
c83f612350
commit
857ac5e95e
@ -0,0 +1,11 @@ |
|||||||
|
# 02: Filter a Log File |
||||||
|
|
||||||
|
In this exercise you'll take a webserver log I've created and parse the log file then filter the log for special events or information. You have a couple of approaches: |
||||||
|
|
||||||
|
|
||||||
|
1. Brute force the filter by simply using a regex to scan the raw text. |
||||||
|
2. Parse each line into meaningful data and filter on that. |
||||||
|
|
||||||
|
The two samples in this directory get you started with both approaches. The `step1.js` file starts off the brute force `RegEx` method while the `step2.js` starts off the parsing method. |
||||||
|
|
||||||
|
Keep in mind these are not solutions. They're starter file so you can get going without having to struggle with all of the setup. Once you're done you should attempt this again but do it entirely from nothing so you know how that's done. |
@ -0,0 +1,15 @@ |
|||||||
|
{ |
||||||
|
"name": "02-filter-a-log-file", |
||||||
|
"version": "1.0.0", |
||||||
|
"description": "", |
||||||
|
"type": "module", |
||||||
|
"main": "step1.js", |
||||||
|
"scripts": { |
||||||
|
"test": "echo \"Error: no test specified\" && exit 1" |
||||||
|
}, |
||||||
|
"author": "", |
||||||
|
"license": "BSD", |
||||||
|
"dependencies": { |
||||||
|
"ava": "^4.3.1" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:55 +0200] "GET /6ce04bf8.js HTTP/2.0" 200 1420 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:55 +0200] "GET /e0335a10.js HTTP/2.0" 200 410 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:55 +0200] "GET /logo.svg HTTP/2.0" 200 836 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:55 +0200] "GET /images/zed.png HTTP/2.0" 200 5666 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:55 +0200] "GET /images/gittea.jpg HTTP/2.0" 200 102800 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:55 +0200] "GET /feather-sprite.svg HTTP/2.0" 200 8993 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:56 +0200] "GET /fonts/computer.woff HTTP/2.0" 200 9416 "https://learnjsthehardway.com/color.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:56 +0200] "GET /favicon.png HTTP/2.0" 200 3127 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:56 +0200] "GET /favicon-32x32.png HTTP/2.0" 200 505 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
||||||
|
1.1.1.1 - - [20/Jul/2022:16:15:57 +0200] "GET /site.webmanifest HTTP/2.0" 200 426 "https://learnjsthehardway.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.1.1.1 Safari/537.36" "-" |
@ -0,0 +1,7 @@ |
|||||||
|
import fs from "fs"; |
||||||
|
|
||||||
|
const raw_log = fs.readFileSync(process.argv[2]); |
||||||
|
|
||||||
|
const lines = raw_log.toString().split("\n"); |
||||||
|
|
||||||
|
console.log(lines); |
Loading…
Reference in new issue