chriso / nginx-parser Goto Github PK
View Code? Open in Web Editor NEWParse nginx logs
License: MIT License
Parse nginx logs
License: MIT License
Should be able to use the built-in zlib.
I called method with parser.read(_path, function(row){})
. and then go in
Parser.prototype.stream = function (stream, iterator, callback) {
var self = this, overflow = new Buffer(0), complete = false;
stream.on('data', function (data) {
var buffer = Buffer.concat(overflow, data), newline = 0;
for (var i = 0, len = buffer.length; i < len; i++) {
if (buffer[i] === 10) {
self.parseLine(buffer.slice(newline, i), iterator);
newline = i + 1;
}
}
overflow = buffer.slice(newline);
});
...
showed me a error message:
"list" argument must be an Array of Buffers。
The overflow wasn't setted value. data was an array.
Could you answer my question?
Thank you very much.
NPM registry has 1.1.0 but repo has 1.2.0 - is there something missing so 1.2.0 isn't release ready yet?
Hello, I'm from the future. I'd like to parse ipv6 addresses for store and nginx_parser
currently fails at this task.
Example code:
var NginxParser = require('nginx_parser');
[...]
var parser = new NginxParser('$remote_addr - $remote_user [$time_local] '
+ '"$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"');
first, nginx_parser is nginxparser
...then, with the example string:
node_modules/nginxparser/index.js:30
this.parser = new RegExp(this.parser);
^
SyntaxError: Invalid regular expression: /([^ ]+) - ([^ ]+) [([^ ]+) "([^ ]+) ([^ ]+) ([^ ]+) "([^ ]+) "(.+)$/: Unmatched ')'
at new RegExp (unknown source)
at new module.exports (node_modules/nginxparser/index.js:30:19)
at Object.<anonymous> (feynman-ui/fetcher.js:11:14)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
So the regular expression generated from the log format gets pinned to the end of the line (looks like the following line of code does it index.js:32 - regex = '(.+)$';). It'd be convenient if the module made it configurable whether to lock to EOL or SOL.
The parser produces a lossy result ie. the result that can't be taken to generate the original input. In particular I'm referring to the translation of dashes/hypens to null (looks like the following line of code does it index.js:170 - if (row[key] === '-') {). Adding this change admittedly wouldn't mean the original line could be generated from the parsed result as we're not tracking the amount of whitespace between each item but. For this change I assume other users of the module are depending on dashes being parsed out as null so when constructing the parser object in addition to providing the format, optional parameters of whether to maintain dashes and whether to pin the regex to end or start of the line could be added.
This module is useful not only for NGiNX, but also Apache or Node.js directly if you're using the logger middleware for Connect: http://www.senchalabs.org/connect/logger.html
I think this should be renamed to something like log_parser
instead.
format = format.replace('[' , '[') should be format = format.replace('[' , '\[')
Something in the regex doesn't like $time_8601
format.
for example
new NginxParser('$remote_addr - $remote_user [$time_8601] ' + '"$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"');
fails to match any lines.
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.