|
@@ -11,18 +11,63 @@ import (
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
+ "git.lattuga.net/boyska/circolog/filtering"
|
|
|
"git.lattuga.net/boyska/circolog/formatter"
|
|
|
"github.com/gorilla/websocket"
|
|
|
+ isatty "github.com/mattn/go-isatty"
|
|
|
+ "github.com/mgutz/ansi"
|
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
)
|
|
|
|
|
|
+type BoolAuto uint
|
|
|
+
|
|
|
+const (
|
|
|
+ BoolAuto_NO BoolAuto = iota
|
|
|
+ BoolAuto_YES BoolAuto = iota
|
|
|
+ BoolAuto_AUTO BoolAuto = iota
|
|
|
+)
|
|
|
+
|
|
|
+func (b *BoolAuto) String() string {
|
|
|
+ switch *b {
|
|
|
+ case BoolAuto_NO:
|
|
|
+ return "no"
|
|
|
+ case BoolAuto_YES:
|
|
|
+ return "always"
|
|
|
+ case BoolAuto_AUTO:
|
|
|
+ return "auto"
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+func (b *BoolAuto) Set(s string) error {
|
|
|
+ switch s {
|
|
|
+ case "auto":
|
|
|
+ *b = BoolAuto_AUTO
|
|
|
+ case "always":
|
|
|
+ *b = BoolAuto_YES
|
|
|
+ case "no":
|
|
|
+ *b = BoolAuto_NO
|
|
|
+ default:
|
|
|
+ return fmt.Errorf("Invalid value %s", s)
|
|
|
+ }
|
|
|
+ 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 filtering.ExprValue
|
|
|
+ flag.Var(&filter, "where", "sql-like query to filter logs")
|
|
|
+ // TODO: change to color-mode=auto/no/always
|
|
|
+ hasColor := BoolAuto_AUTO
|
|
|
+ flag.Var(&hasColor, "color", "dis/enable colors")
|
|
|
flag.Parse()
|
|
|
|
|
|
+ if hasColor == BoolAuto_NO || (!isatty.IsTerminal(os.Stdout.Fd()) && hasColor != BoolAuto_YES) {
|
|
|
+ ansi.DisableColors(true)
|
|
|
+ }
|
|
|
+
|
|
|
interrupt := make(chan os.Signal, 1)
|
|
|
signal.Notify(interrupt, os.Interrupt)
|
|
|
var d *websocket.Dialer
|
|
@@ -69,7 +114,10 @@ func main() {
|
|
|
}
|
|
|
var parsed format.LogParts
|
|
|
if err := bson.Unmarshal(serialized, &parsed); err != nil {
|
|
|
- log.Println("invalid YAML", err)
|
|
|
+ log.Println("invalid BSON", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if !filter.Validate(parsed) {
|
|
|
continue
|
|
|
}
|
|
|
if err := formatter.WriteFormatted(os.Stdout, formatter.FormatSyslog, parsed); err != nil {
|