Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit e2d841e

Browse files
committed
feat: add follow option
1 parent b3c5442 commit e2d841e

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

common/options.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
type Options struct {
1111
Concurrency int // Set the concurrent level
1212
ConfigFile string // Specifies the config to use
13-
Stdin bool // Stdin specifies whether stdin input was given to the process
14-
Version bool // Version check of teler flag
15-
Input string // Parse log from data persistence rather than buffer stream
16-
Output *os.File // Write log output into file
1713
Configs *parsers.Configs // Get teler configuration interface
14+
Follow bool // Specify if the logs should be streamed
15+
Input string // Parse log from data persistence rather than buffer stream
1816
JSON bool // Display threats in the terminal as JSON format
17+
Output *os.File // Write log output into file
1918
RmCache bool // To remove all cached resources on local
19+
Stdin bool // Stdin specifies whether stdin input was given to the process
20+
Version bool // Version check of teler flag
2021
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
99
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d
1010
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
11+
github.com/kitabisa/tailpipe v1.0.0
1112
github.com/logrusorgru/aurora v2.0.3+incompatible
1213
github.com/panjf2000/ants/v2 v2.5.0
1314
github.com/projectdiscovery/gologger v1.1.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNq
161161
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0=
162162
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
163163
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
164+
github.com/kitabisa/tailpipe v1.0.0 h1:/dBte3xpjDbUsHnOILJaEryX5VA65w2Dxy6JbhViwXY=
165+
github.com/kitabisa/tailpipe v1.0.0/go.mod h1:298TbGVS9RP6sqxtJXg7rPTAZVGBhWIWRHaF1JbborQ=
164166
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
165167
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
166168
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=

internal/runner/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ func ParseOptions() *common.Options {
2222
flag.StringVar(&options.Input, "i", "", "")
2323
flag.StringVar(&options.Input, "input", "", "")
2424

25+
flag.BoolVar(&options.Follow, "f", false, "")
26+
flag.BoolVar(&options.Follow, "follow", false, "")
27+
2528
flag.IntVar(&options.Concurrency, "x", 20, "")
2629
flag.IntVar(&options.Concurrency, "concurrent", 20, "")
2730

@@ -43,6 +46,7 @@ func ParseOptions() *common.Options {
4346
"Options:",
4447
" -c, --config <FILE> teler configuration file",
4548
" -i, --input <FILE> Analyze logs from data persistence rather than buffer stream",
49+
" -f, --follow Specify if the logs should be streamed",
4650
" -x, --concurrent <i> Set the concurrency level to analyze logs (default: 20)",
4751
" --rm-cache Removes all cached resources",
4852
" -v, --version Show current teler version",

internal/runner/runner.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/signal"
88

9+
"github.com/kitabisa/tailpipe"
910
"github.com/logrusorgru/aurora"
1011
"github.com/panjf2000/ants/v2"
1112
"github.com/projectdiscovery/gologger"
@@ -22,8 +23,9 @@ import (
2223
// New read & pass stdin log
2324
func New(options *common.Options) {
2425
var (
25-
input *os.File
26-
pass int
26+
reader *gonx.Reader
27+
input *os.File
28+
pass int
2729
)
2830

2931
go metric(options)
@@ -83,9 +85,20 @@ func New(options *common.Options) {
8385

8486
config := options.Configs
8587
format := removeLBR(config.Logformat)
86-
buffer := gonx.NewReader(input, format)
88+
89+
if !options.Stdin && options.Follow {
90+
f, e := tailpipe.Open(options.Input)
91+
if e != nil {
92+
errors.Exit(e.Error())
93+
}
94+
95+
reader = gonx.NewReader(f, format)
96+
} else {
97+
reader = gonx.NewReader(input, format)
98+
}
99+
87100
for {
88-
line, err := buffer.Read()
101+
line, err := reader.Read()
89102
if err == io.EOF {
90103
break
91104
}

0 commit comments

Comments
 (0)