Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide mechanisms to forward output from jnlp app #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.
type Options struct {
IsRunningFromBrowser bool
JavaDir string
ShowConsole bool
DisableVerification bool
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.

None yet

1 participant