Merge pull request #4290 from dokku/debug-output

Add support for debug logging plugin trigger stderr and stdout
This commit is contained in:
Jose Diaz-Gonzalez
2021-01-02 18:40:15 -05:00
committed by GitHub
3 changed files with 36 additions and 17 deletions

View File

@@ -74,13 +74,10 @@ func GetAppScheduler(appName string) string {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...) appScheduler = getAppScheduler(appName)
value := strings.TrimSpace(string(b[:]))
if value != "" {
appScheduler = value
}
}() }()
} }
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
@@ -95,6 +92,15 @@ func GetAppScheduler(appName string) string {
return appScheduler return appScheduler
} }
func getAppScheduler(appName string) string {
b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...)
value := strings.TrimSpace(string(b[:]))
if value != "" {
return value
}
return ""
}
// GetGlobalScheduler fetchs the global scheduler // GetGlobalScheduler fetchs the global scheduler
func GetGlobalScheduler() string { func GetGlobalScheduler() string {
b, _ := PlugnTriggerOutput("config-get-global", []string{"DOKKU_SCHEDULER"}...) b, _ := PlugnTriggerOutput("config-get-global", []string{"DOKKU_SCHEDULER"}...)

View File

@@ -110,7 +110,7 @@ func LogStderr(text string) {
// LogDebug is the debug log formatter // LogDebug is the debug log formatter
func LogDebug(text string) { func LogDebug(text string) {
if os.Getenv("DOKKU_TRACE") == "" { if os.Getenv("DOKKU_TRACE") == "1" {
fmt.Fprintln(os.Stderr, fmt.Sprintf(" ? %s", text)) fmt.Fprintln(os.Stderr, fmt.Sprintf(" ? %s", strings.TrimPrefix(text, " ? ")))
} }
} }

View File

@@ -80,21 +80,34 @@ func PlugnTrigger(triggerName string, args ...string) error {
// PlugnTriggerOutput fire the given plugn trigger with the given args // PlugnTriggerOutput fire the given plugn trigger with the given args
func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) { func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) {
rescueStderr := os.Stderr LogDebug(fmt.Sprintf("plugn trigger %s %v", triggerName, args))
r, w, _ := os.Pipe() rE, wE, _ := os.Pipe()
os.Stderr = w rO, wO, _ := os.Pipe()
out, err := PlugnTriggerSetup(triggerName, args...).Output() session := PlugnTriggerSetup(triggerName, args...)
w.Close() session.Stderr = wE
session.Stdout = wO
err := session.Run()
wE.Close()
wO.Close()
readStderr, _ := ioutil.ReadAll(r) readStderr, _ := ioutil.ReadAll(rE)
os.Stderr = rescueStderr readStdout, _ := ioutil.ReadAll(rO)
var stderr error stderr := string(readStderr[:])
if err != nil { if err != nil {
stderr = fmt.Errorf(string(readStderr[:])) err = fmt.Errorf(stderr)
} }
return out, stderr if os.Getenv("DOKKU_TRACE") == "1" {
for _, line := range strings.Split(stderr, "\n") {
LogDebug(fmt.Sprintf("plugn trigger %s stderr: %s", triggerName, line))
}
for _, line := range strings.Split(string(readStdout[:]), "\n") {
LogDebug(fmt.Sprintf("plugn trigger %s stdout: %s", triggerName, line))
}
}
return readStdout, err
} }
// PlugnTriggerSetup sets up a plugn trigger call // PlugnTriggerSetup sets up a plugn trigger call