1.0.9
This commit is contained in:
parent
7f8b2e4f7a
commit
3ecf33036c
@ -82,3 +82,30 @@ export function getRelativeTime(date) {
|
|||||||
|
|
||||||
return '很久以前';
|
return '很久以前';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 解析nginx日志(单行)
|
||||||
|
* @param {string} log
|
||||||
|
*/
|
||||||
|
function parseNginxLog (log) {
|
||||||
|
const logPattern = /^(\S+) - - \[([^\]]+)\] "(\S+) (\S+) HTTP\/\d\.\d" (\d+) (\d+) "([^"]*)" "([^"]*)"/;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const match = log.match(logPattern);
|
||||||
|
if (match) {
|
||||||
|
return {
|
||||||
|
ip: match[1],
|
||||||
|
timestamp: match[2],
|
||||||
|
method: match[3],
|
||||||
|
url: match[4],
|
||||||
|
status: parseInt(match[5]),
|
||||||
|
responseSize: parseInt(match[6]),
|
||||||
|
referrer: match[7],
|
||||||
|
userAgent: match[8],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
2
index.js
2
index.js
@ -8,6 +8,6 @@
|
|||||||
* @FilePath: /index.js
|
* @FilePath: /index.js
|
||||||
*/
|
*/
|
||||||
export { animateStart, setClassVar, getStyleVar } from './Tool/animate.js';
|
export { animateStart, setClassVar, getStyleVar } from './Tool/animate.js';
|
||||||
export { randomNum, nextArray, ArrayDeHeavy, getRelativeTime } from './Tool/number.js';
|
export { randomNum, nextArray, ArrayDeHeavy, getRelativeTime, parseNginxLog } from './Tool/number.js';
|
||||||
|
|
||||||
console.log('ddmt-tool Loading successfully!! 😺');
|
console.log('ddmt-tool Loading successfully!! 😺');
|
1
types/index.d.ts
vendored
1
types/index.d.ts
vendored
@ -8,5 +8,6 @@ declare module 'ddmt-tool' {
|
|||||||
export function randomNum(minNum: number): number;
|
export function randomNum(minNum: number): number;
|
||||||
export function randomNum(minNum: number, maxNum: number): number;
|
export function randomNum(minNum: number, maxNum: number): number;
|
||||||
export function nextArray(arr: any[], index: number): any[];
|
export function nextArray(arr: any[], index: number): any[];
|
||||||
|
export function parseNginxLog(log: string): object;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user