Support scraper logging to specific log levels (#1648)

* init scrapper log levels
* Refactor plugin logging

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
stg-annon
2021-09-16 19:09:44 -04:00
committed by GitHub
parent 501ed7c2c2
commit d29699fa30
5 changed files with 244 additions and 161 deletions

View File

@@ -1,7 +1,6 @@
package scraper
import (
"bufio"
"encoding/json"
"errors"
"io"
@@ -66,12 +65,7 @@ func (s *scriptScraper) runScraperScript(inString string, out interface{}) error
return errors.New("error running scraper script")
}
scanner := bufio.NewScanner(stderr)
go func() { // log errors from stderr pipe
for scanner.Scan() {
logger.Errorf("scraper: %s", scanner.Text())
}
}()
go handleScraperStderr(stderr)
logger.Debugf("Scraper script <%s> started", strings.Join(cmd.Args, " "))
@@ -253,3 +247,13 @@ func findPythonExecutable() (string, error) {
return "python3", nil
}
func handleScraperStderr(scraperOutputReader io.ReadCloser) {
const scraperPrefix = "[Scrape] "
lgr := logger.PluginLogger{
Prefix: scraperPrefix,
DefaultLogLevel: &logger.ErrorLevel,
}
lgr.HandlePluginStdErr(scraperOutputReader)
}