Last active
May 8, 2018 13:07
-
-
Save afrontend/071eb8cf8985469d51adaeaf306f1dd9 to your computer and use it in GitHub Desktop.
로그 파일에서 시간 간격 추출하기, https://agvim.wordpress.com/2018/05/08/generate-text-time-interval-from-log-file/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const cli = require('cli'), | |
moment = require('moment'), | |
config = require('./config'); | |
function getAndroidTimeStr(str) { | |
const timeRe = /^\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d/; | |
let resultStr = timeRe.exec(str); | |
return resultStr === null ? "" : resultStr[0]; | |
} | |
function getAndroidTimeDiff(prev_time, cur_time) { | |
let cur_m_time, | |
prev_m_time; | |
prev_m_time = moment(prev_time, "MM-DD HH:mm:ss.SSS"); | |
cur_m_time = moment(cur_time, "MM-DD HH:mm:ss.SSS"); | |
return (cur_m_time.valueOf() - prev_m_time.valueOf()); | |
} | |
let line_number = 0, | |
cur_time, | |
prev_time, | |
start_time, | |
re; | |
cli.withInput(function (line, newline, eof) { | |
line_number = line_number + 1; | |
if (!eof) { | |
//console.log(line, "####", line_number); | |
let i = 0, | |
length = config.length; | |
for(i = 0; i < length; i++) { | |
let pattern = config[i].pattern, | |
desc = config[i].description; | |
re = new RegExp(pattern); | |
if(line.match(re)) { | |
cur_time = getAndroidTimeStr(line); | |
if(prev_time === undefined) { | |
prev_time = cur_time; | |
start_time = cur_time; | |
} | |
console.log(getAndroidTimeDiff(start_time, cur_time) + "ms", "(~" + getAndroidTimeDiff(prev_time, cur_time) + "ms)", desc, "#", line_number); | |
prev_time = cur_time; | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment