blarsen / node-alpine Goto Github PK
View Code? Open in Web Editor NEWAlpine - the Apache Log Parser for Node.js
License: Apache License 2.0
Alpine - the Apache Log Parser for Node.js
License: Apache License 2.0
Alpine successfully handles a log format with a single field inside quotes, e.g.
var alpine = new Alpine("\"%h\"");
However it doesn't like it if the log format has multiple fields inside the same set of quotes, e.g.
var alpine = new Alpine("\"%h %h\"");
I believe having multiple fields inside the same set of quotes is a valid scenario.
The stacktrace:
S:\dev\scratch\node_modules\alpine\alpine.js:110
throw new Error("Field does not start with %: "+field);
^
Error: Field does not start with %: "%h
at parseLogFormat (S:\dev\scratch\node_modules\alpine\alpine.js:110:19)
at setLogFormat (S:\dev\scratch\node_modules\alpine\alpine.js:65:25)
at new Alpine (S:\dev\scratch\node_modules\alpine\alpine.js:25:14)
at Object.<anonymous> (S:\dev\scratch\selflog2sp.js:4:14)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
Parser requires time to be in brackets. I'm assuming this is a convenient assumption. It makes it easy to find all the data, even if they contain spaces. However, AWS ELB logs use ISO-8601 format without brackets.
Example: 2019-06-29T12:40:00.547997Z
This is a very common, portable, and parsable date format. It should be supported with a new format field.
Great package!
I am using this and found that if one log line fails it kills the script.
I thought it would be better if the parseLine method had a catch in case for any reason one log line was poorly formatted and it doesn't affect the whole parsing operation. I think the best case would be to be able to pass a custom error handler when there is a message.
Just a small thought as an enhancement. Thank you so much!
try {
this.formatfields.forEach(function(field) {
buf.skipSpaces();
var val;
if (field.isQuoted) {
if (!(buf.lookingAt() === '"'))
throw new Error("Field defined as quoted was not quoted");
buf.skip();
val = buf.getUpto('"');
buf.skip();
} else if (field.isDate) {
if (!(buf.lookingAt() === '['))
throw new Error("Time field is not enclosed in brackets");
buf.skip();
val = buf.getUpto(']');
buf.skip();
} else {
val = buf.getUpto(' ');
}
result[field.name] = val;
})
} catch (e) {
result.error = e.message;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.