|
@@ -11,41 +11,18 @@ import (
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
+ "git.lattuga.net/boyska/circolog/filtering"
|
|
|
"git.lattuga.net/boyska/circolog/formatter"
|
|
|
- "github.com/araddon/qlbridge/datasource"
|
|
|
- "github.com/araddon/qlbridge/expr"
|
|
|
- "github.com/araddon/qlbridge/value"
|
|
|
- "github.com/araddon/qlbridge/vm"
|
|
|
"github.com/gorilla/websocket"
|
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
)
|
|
|
|
|
|
-type ExprValue struct {
|
|
|
- Node expr.Node
|
|
|
-}
|
|
|
-
|
|
|
-func (e *ExprValue) String() string {
|
|
|
- if e.Node != nil {
|
|
|
- return e.Node.String()
|
|
|
- } else {
|
|
|
- return "<Empty Expression>"
|
|
|
- }
|
|
|
-}
|
|
|
-func (e *ExprValue) Set(value string) error {
|
|
|
- ast, err := expr.ParseExpression(value)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- e.Node = ast
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
func main() {
|
|
|
addr := flag.String("addr", "localhost:9080", "http service address")
|
|
|
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
|
|
|
backlogLimit := flag.Int("n", -1, "Limit the backlog length, defaults to no limit (-1)")
|
|
|
- var filter ExprValue
|
|
|
+ var filter filtering.ExprValue
|
|
|
flag.Var(&filter, "where", "sql-like query to filter logs")
|
|
|
flag.Parse()
|
|
|
|
|
@@ -98,19 +75,8 @@ func main() {
|
|
|
log.Println("invalid BSON", err)
|
|
|
continue
|
|
|
}
|
|
|
- if filter.Node != nil {
|
|
|
- context := datasource.NewContextSimpleNative(parsed)
|
|
|
- val, ok := vm.Eval(context, filter.Node)
|
|
|
- if !ok || val == nil { // errors when evaluating
|
|
|
- continue
|
|
|
- }
|
|
|
- if val.Type() != value.BoolType {
|
|
|
- fmt.Fprintln(os.Stderr, "WARNING: The 'where' expression doesn't return a boolean")
|
|
|
- continue
|
|
|
- }
|
|
|
- if val.Value().(bool) != true {
|
|
|
- continue
|
|
|
- }
|
|
|
+ if filter.Node != nil && !filter.Validate(parsed) {
|
|
|
+ continue
|
|
|
}
|
|
|
if err := formatter.WriteFormatted(os.Stdout, formatter.FormatSyslog, parsed); err != nil {
|
|
|
log.Println("error printing", err)
|