Warn when log file in explain command is large. (#1293)
* Warn when log file in explain command is large. Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
This commit is contained in:
parent
45c1075ae0
commit
0f5e922851
1 changed files with 19 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -51,7 +52,6 @@ cscli explain --dsn "file://myfile.log" --type nginx
|
|||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(logLine)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ cscli explain --dsn "file://myfile.log" --type nginx
|
|||
log.Fatalf("unable to get absolue path of '%s', exiting", logFile)
|
||||
}
|
||||
dsn = fmt.Sprintf("file://%s", absolutePath)
|
||||
lineCount := getLineCountForFile(absolutePath)
|
||||
if lineCount > 100 {
|
||||
log.Warnf("log file contains %d lines. This may take lot of resources.", lineCount)
|
||||
}
|
||||
}
|
||||
|
||||
if dsn == "" {
|
||||
|
@ -108,3 +112,17 @@ cscli explain --dsn "file://myfile.log" --type nginx
|
|||
|
||||
return cmdExplain
|
||||
}
|
||||
|
||||
func getLineCountForFile(filepath string) int {
|
||||
f, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to open log file %s", filepath)
|
||||
}
|
||||
defer f.Close()
|
||||
lc := 0
|
||||
fs := bufio.NewScanner(f)
|
||||
for fs.Scan() {
|
||||
lc++
|
||||
}
|
||||
return lc
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue