5
5
"fmt"
6
6
"log/slog"
7
7
"os"
8
- "regexp"
9
8
"sync"
10
9
11
10
"github.com/jasonlvhit/gocron"
@@ -29,7 +28,7 @@ func main() {
29
28
validate ()
30
29
31
30
if f .Test {
32
- testIt ( )
31
+ pkg . TestIt ( f . FilePath , f . Match )
33
32
return
34
33
}
35
34
@@ -221,34 +220,6 @@ func notify(result *pkg.ScanResult) {
221
220
}
222
221
}
223
222
224
- func testIt () {
225
- fps , err := pkg .FilesByPattern (f .FilePath )
226
- if err != nil {
227
- slog .Error ("Error finding files" , "error" , err .Error ())
228
- }
229
- slog .Info ("Files found" , "count" , len (fps ))
230
- for _ , filePath := range fps {
231
- slog .Info ("Found file" , "filePath" , filePath )
232
- }
233
- str := pkg .ReadFromPipeInput ()
234
- if str == "" {
235
- slog .Error ("No input found" )
236
- slog .Info ("Usage echo 'test123' | go-watch-logs --match=123 -test" )
237
- return
238
- }
239
- str = str [:len (str )- 1 ] // strip new line
240
- re , err := regexp .Compile (f .Match )
241
- if err != nil {
242
- slog .Error ("Error compiling regex" , "error" , err .Error ())
243
- return
244
- }
245
- if re .Match ([]byte (str )) {
246
- slog .Info ("Matched" , "Match Regex" , f .Match , "input" , str , "Match Found" , re .FindString (str ))
247
- } else {
248
- slog .Warn ("Not matched" , "Match" , f .Match , "str" , str )
249
- }
250
- }
251
-
252
223
func flags () {
253
224
flag .StringVar (& f .FilePath , "file-path" , "" , "full path to the log file" )
254
225
flag .StringVar (& f .FilePath , "f" , "" , "(short for --file-path) full path to the log file" )
0 commit comments