Parse and serialize LogQL query
- Node.js version 18 or higher
This package is available in the Node Package Repository and can be easily installed with npm or yarn
$ npm i @sigyn/logql
# or
$ yarn add @sigyn/logql
Build your LogQL
import { LogQL } from "@sigyn/logql";
const logql = new LogQL("foo");
logql.streamSelector.set("env", "prod");
logql.lineEq("bar");
logql.lineNotEq("baz");
// {env=\"prod\"} |= `foo` |= `bar` != `baz`
console.log(logql.toString());
Parse your LogQL
import { LogQL } from "@sigyn/logql";
const logql = new LogQL("{app=\"foo\", env=\"preprod\"} |= `foo` != `bar`");
console.log([...logql.streamSelector.entries()]);
console.log(logql.lineFilters.lineContains());
console.log(logql.lineFilters.lineDoesNotContain());
Individual LogQL parts (used in the parent class). You can also use them individually for separate needs.
{env="staging"} |= "req-xxx" | pattern `ok: <ok>` | ok = "true" | unpack
^^^ ^^^ ^^^ ^^^ ^
StreamSelector LineFilters ParserExpression LabelFilters ParserExpression
MIT