Skip to content

Conversation

@klarose
Copy link

@klarose klarose commented Aug 17, 2022

A misbehaving application may log information to stderr, or even stdout.
Sometimes it is useful to collect this information for diagnostic
purposes. Provide a mechanism to capture this output in a customizable
fashion using callback functions invoked on a goroutine with the
stdin/stderr pipe returned from the exec.Cmd we launch.

An example of using this:

// makeLauncher makes a launcher configured to forward the launched applications stdout to logrus's Info level, and stderr to logrus's Error level.
func makeLauncher() launcher.Launcher {
	options := &launcher.Options{
		StdoutHandler: pipeLogger(logrus.Info),
		StderrHandler: pipeLogger(logrus.Error),
	}
        jnlpLauncher := jnlp.NewLauncher()
        jnlpLauncher.SetOptions(options)
       return jnlpLauncher
}

func pipeLogger(outFunc func(args ...interface{})) func(io.ReadCloser) {
	return func(input io.ReadCloser) {
		defer input.Close()
		scanner := bufio.NewScanner(input)
		for scanner.Scan() {
			outFunc(scanner.Text())
		}
	}
}

A misbehaving application may log information to stderr, or even stdout.
Sometimes it is useful to collect this information for diagnostic
purposes. Provide a mechanism to capture this output in a customizable
fashion using callback functions invoked on a goroutine with the
stdin/stderr pipe returned from the exec.Cmd we launch.
DisableVerificationSameOrigin bool

// If non-nil, processes output from stdout of the launched process
StdoutHandler OutputHandler
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to this would be to add it to the interface. I chose the options to limit the requirements of the interface, but I'm good with either approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant