Compare commits
No commits in common. "master" and "master" have entirely different histories.
2 changed files with 9 additions and 48 deletions
12
README.md
12
README.md
|
@ -1,14 +1,2 @@
|
|||
# log-export
|
||||
|
||||
Example for the frostfs-node:
|
||||
```
|
||||
go run ./cmd -funcs reportFlushError,reportError -dir ../frostfs-node
|
||||
```
|
||||
|
||||
Command line flags:
|
||||
|
||||
```
|
||||
-funcs - custom functions to export separated by ','
|
||||
|
||||
-dir - source code directory
|
||||
```
|
45
cmd/main.go
45
cmd/main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
|
@ -9,25 +8,14 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
customLogs = flag.String("funcs", "", "Custom functions to export delimited by ','.")
|
||||
directory = flag.String("dir", "", "Source code directory.")
|
||||
methodsToSearchOnce = &sync.Once{}
|
||||
methodsToSearch = []string{"Debug", "Info", "Warn", "Error"}
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if len(*directory) == 0 {
|
||||
if len(os.Args) != 2 {
|
||||
log.Fatalln("directory must be provided")
|
||||
}
|
||||
|
||||
directories, err := getAllSubdirectories(*directory)
|
||||
directories, err := getAllSubdirectories(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatalf("failed to list subdirs: %v", err)
|
||||
}
|
||||
|
@ -45,10 +33,9 @@ func main() {
|
|||
if !ok {
|
||||
return true
|
||||
}
|
||||
isLog, logMethod := isLogDot(expr.Fun)
|
||||
if isLog && len(expr.Args) > 0 && isStringValue(expr.Args[0]) {
|
||||
if isLogDot(expr.Fun) && len(expr.Args) > 0 && isStringValue(expr.Args[0]) {
|
||||
position := fset.Position(expr.Pos())
|
||||
fmt.Printf("%v %s:%s\n", position, logMethod, stringValue(expr.Args[0]))
|
||||
fmt.Printf("%v %s\n", position, stringValue(expr.Args[0]))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -86,26 +73,12 @@ func getAllSubdirectories(dir string) ([]string, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func isLogDot(expr ast.Expr) (bool, string) {
|
||||
func isLogDot(expr ast.Expr) bool {
|
||||
sel, ok := expr.(*ast.SelectorExpr)
|
||||
if !ok {
|
||||
return false, ""
|
||||
}
|
||||
methodsToSearchOnce.Do(func() {
|
||||
for _, cl := range strings.Split(*customLogs, ",") {
|
||||
cl = strings.Trim(cl, " ")
|
||||
if len(cl) > 0 {
|
||||
methodsToSearch = append(methodsToSearch, cl)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
for _, method := range methodsToSearch {
|
||||
if isIdent(sel.Sel, method) {
|
||||
return true, method
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
return ok && (isIdent(sel.Sel, "Debug") ||
|
||||
isIdent(sel.Sel, "Info") ||
|
||||
isIdent(sel.Sel, "Warn") ||
|
||||
isIdent(sel.Sel, "Error"))
|
||||
}
|
||||
|
||||
func isIdent(expr ast.Expr, ident string) bool {
|
||||
|
|
Loading…
Reference in a new issue