summaryrefslogtreecommitdiff
path: root/cmd/dgrep
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2021-10-15 12:38:39 +0300
committerPaul Buetow <pbuetow@mimecast.com>2021-10-15 12:38:39 +0300
commit1edc1469024d3cb74473bd99959d5d1068229c39 (patch)
tree72618e384626d9fc368994e3f24be9e9892d0610 /cmd/dgrep
parent4e1b7f6ff7e3f10bda852da90f7b62d5dbccd455 (diff)
parentc0332e8fa13f4939de17c856b2e71fd093847253 (diff)
merge from github.com/snonux/dtail
Diffstat (limited to 'cmd/dgrep')
-rw-r--r--cmd/dgrep/main.go60
1 files changed, 40 insertions, 20 deletions
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 133631f..602d318 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -3,67 +3,87 @@ package main
import (
"context"
"flag"
+ "fmt"
"os"
+ "sync"
+
+ "net/http"
+ _ "net/http"
+ _ "net/http/pprof"
"github.com/mimecast/dtail/internal/clients"
- "github.com/mimecast/dtail/internal/color"
"github.com/mimecast/dtail/internal/config"
- "github.com/mimecast/dtail/internal/io/logger"
+ "github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
+ "github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
)
// The evil begins here.
func main() {
- var args clients.Args
- var cfgFile string
- var debugEnable bool
+ var args config.Args
var displayVersion bool
var grep string
- var noColor bool
- var sshPort int
-
+ var pprof int
userName := user.Name()
+ flag.BoolVar(&args.NoColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&args.Quiet, "quiet", false, "Quiet output mode")
flag.BoolVar(&args.RegexInvert, "invert", false, "Invert regex")
- flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
+ flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Trust all unknown host keys")
flag.BoolVar(&displayVersion, "version", false, "Display version")
- flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
- flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
- flag.IntVar(&sshPort, "port", 2222, "SSH server port")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU,
+ "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines")
+ flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines")
+ flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines")
+ flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
+ flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
+ flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path")
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.LogDir, "logDir", "~/log", "Log dir")
+ flag.StringVar(&args.Logger, "logger", config.DefaultClientLogger, "Logger name")
+ flag.StringVar(&args.LogLevel, "logLevel", config.DefaultLogLevel, "Log level")
flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
flag.StringVar(&args.UserName, "user", userName, "Your system user name")
flag.StringVar(&args.What, "files", "", "File(s) to read")
- flag.StringVar(&cfgFile, "cfg", "", "Config file path")
flag.StringVar(&grep, "grep", "", "Alias for -regex")
flag.Parse()
-
- config.Read(cfgFile, sshPort)
- color.Colored = !noColor
+ config.Setup(source.Client, &args, flag.Args())
if displayVersion {
version.PrintAndExit()
}
- ctx := context.TODO()
- logger.Start(ctx, logger.Modes{Debug: debugEnable || config.Common.DebugEnable})
+ ctx, cancel := context.WithCancel(context.Background())
+ var wg sync.WaitGroup
+ wg.Add(1)
+ dlog.Start(ctx, &wg, source.Client)
if grep != "" {
args.RegexStr = grep
}
+ if pprof > -1 {
+ // For debugging purposes only
+ pprofArgs := fmt.Sprintf("0.0.0.0:%d", pprof)
+ go http.ListenAndServe(pprofArgs, nil)
+ dlog.Client.Info("Started PProf", pprofArgs)
+ }
+
client, err := clients.NewGrepClient(args)
if err != nil {
panic(err)
}
status := client.Start(ctx, signal.InterruptCh(ctx))
- logger.Flush()
+ cancel()
+
+ wg.Wait()
os.Exit(status)
}