forked from dstepanov-yadro/log-export
cmd: allow to provide custom functions for export
As an example for the frostfs-node: ``` go run ./cmd -funcs reportFlushError,reportError ../node ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
e232bfeef4
commit
72a7b2eca0
1 changed files with 31 additions and 3 deletions
34
cmd/main.go
34
cmd/main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
|
@ -8,14 +9,21 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
customLogs = flag.String("funcs", "", "Custom functions to export delimited by ','.")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 2 {
|
flag.Parse()
|
||||||
|
|
||||||
|
if flag.NArg() != 1 {
|
||||||
log.Fatalln("directory must be provided")
|
log.Fatalln("directory must be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
directories, err := getAllSubdirectories(os.Args[1])
|
directories, err := getAllSubdirectories(flag.Arg(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to list subdirs: %v", err)
|
log.Fatalf("failed to list subdirs: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +86,27 @@ func isLogDot(expr ast.Expr) bool {
|
||||||
return ok && (isIdent(sel.Sel, "Debug") ||
|
return ok && (isIdent(sel.Sel, "Debug") ||
|
||||||
isIdent(sel.Sel, "Info") ||
|
isIdent(sel.Sel, "Info") ||
|
||||||
isIdent(sel.Sel, "Warn") ||
|
isIdent(sel.Sel, "Warn") ||
|
||||||
isIdent(sel.Sel, "Error"))
|
isIdent(sel.Sel, "Error") ||
|
||||||
|
isCustomLog(sel.Sel))
|
||||||
|
}
|
||||||
|
|
||||||
|
func isCustomLog(expr ast.Expr) bool {
|
||||||
|
id, ok := expr.(*ast.Ident)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(*customLogs) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
ss := strings.Split(*customLogs, ",")
|
||||||
|
for i := range ss {
|
||||||
|
if id.Name == ss[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isIdent(expr ast.Expr, ident string) bool {
|
func isIdent(expr ast.Expr, ident string) bool {
|
||||||
|
|
Loading…
Reference in a new issue