Scraper log improvements (#1741)

* Fix logs from scraper and plugins not being shown in UI

Using `logger.` in the logger package to write logs is "incorrect". This
as the package contains a variable named `logger` which contains the
logrus instance. So instead of the log line being handled by the custom
log implementation / wrapper which makes sure the lines are shown in the
UI as well, it's written to logrus directly meaning the wrapper is
skipped.

This "issue" is obviously triggered because in any other place
`logger.X` can be used and it will used the custom logger package /
wrapper which works fine.

* Add plugin / scraper name to logging output

Indicate which plugin / scraper wrote a log message by including its
name to the `[Scrape]` prefix.

* Add missing addLogItem call
This commit is contained in:
gitgiggety 2021-09-19 02:06:34 +02:00 committed by GitHub
parent 66f92c5dcc
commit b83ce29ac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 15 deletions

View file

@ -182,6 +182,11 @@ func Progressf(format string, args ...interface{}) {
func Trace(args ...interface{}) {
logger.Trace(args...)
l := &LogItem{
Type: "trace",
Message: fmt.Sprint(args...),
}
addLogItem(l)
}
func Tracef(format string, args ...interface{}) {

View file

@ -146,19 +146,19 @@ func (log *PluginLogger) HandleStderrLine(line string) {
switch *level {
case TraceLevel:
logger.Trace(log.Prefix, ll)
Trace(log.Prefix, ll)
case DebugLevel:
logger.Debug(log.Prefix, ll)
Debug(log.Prefix, ll)
case InfoLevel:
logger.Info(log.Prefix, ll)
Info(log.Prefix, ll)
case WarningLevel:
logger.Warn(log.Prefix, ll)
Warn(log.Prefix, ll)
case ErrorLevel:
logger.Error(log.Prefix, ll)
Error(log.Prefix, ll)
case ProgressLevel:
p, err := strconv.ParseFloat(ll, 64)
if err != nil {
logger.Errorf("Error parsing progress value '%s': %s", ll, err.Error())
Errorf("Error parsing progress value '%s': %s", ll, err.Error())
} else {
// only pass progress through if channel present
if log.ProgressChan != nil {

View file

@ -1,22 +1,23 @@
package plugin
import (
"fmt"
"io"
"github.com/stashapp/stash/pkg/logger"
)
func (t *pluginTask) handlePluginStderr(pluginOutputReader io.ReadCloser) {
func (t *pluginTask) handlePluginStderr(name string, pluginOutputReader io.ReadCloser) {
logLevel := logger.PluginLogLevelFromName(t.plugin.PluginErrLogLevel)
if logLevel == nil {
// default log level to error
logLevel = &logger.ErrorLevel
}
const pluginPrefix = "[Plugin] "
const pluginPrefix = "[Plugin / %s] "
lgr := logger.PluginLogger{
Prefix: pluginPrefix,
Prefix: fmt.Sprintf(pluginPrefix, name),
DefaultLogLevel: logLevel,
ProgressChan: t.progress,
}

View file

@ -70,7 +70,7 @@ func (t *rawPluginTask) Start() error {
return fmt.Errorf("error running plugin: %s", err.Error())
}
go t.handlePluginStderr(stderr)
go t.handlePluginStderr(t.plugin.Name, stderr)
t.cmd = cmd
// send the stdout to the plugin output

View file

@ -64,7 +64,7 @@ func (t *rpcPluginTask) Start() error {
return err
}
go t.handlePluginStderr(pluginErrReader)
go t.handlePluginStderr(t.plugin.Name, pluginErrReader)
iface := rpcPluginClient{
Client: t.client,

View file

@ -3,6 +3,7 @@ package scraper
import (
"encoding/json"
"errors"
"fmt"
"io"
"os/exec"
"path/filepath"
@ -65,7 +66,7 @@ func (s *scriptScraper) runScraperScript(inString string, out interface{}) error
return errors.New("error running scraper script")
}
go handleScraperStderr(stderr)
go handleScraperStderr(s.config.Name, stderr)
logger.Debugf("Scraper script <%s> started", strings.Join(cmd.Args, " "))
@ -248,11 +249,11 @@ func findPythonExecutable() (string, error) {
return "python3", nil
}
func handleScraperStderr(scraperOutputReader io.ReadCloser) {
const scraperPrefix = "[Scrape] "
func handleScraperStderr(name string, scraperOutputReader io.ReadCloser) {
const scraperPrefix = "[Scrape / %s] "
lgr := logger.PluginLogger{
Prefix: scraperPrefix,
Prefix: fmt.Sprintf(scraperPrefix, name),
DefaultLogLevel: &logger.ErrorLevel,
}
lgr.HandlePluginStdErr(scraperOutputReader)