Skip to content

Commit

Permalink
Pass stdout, stderr to the app process correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 25, 2019
1 parent 3a51ddd commit bdaa7b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 5 additions & 1 deletion pkg/app2/appserver/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package appserver

import (
"fmt"
"io"
"os/exec"
"path/filepath"

Expand All @@ -20,7 +21,7 @@ type Proc struct {
}

// NewProc constructs `Proc`.
func NewProc(log *logging.Logger, c Config, args []string) (*Proc, error) {
func NewProc(log *logging.Logger, c Config, args []string, stdout, stderr io.Writer) (*Proc, error) {
key := GenerateAppKey()

binaryPath := getBinaryPath(c.BinaryDir, c.Name, c.Version)
Expand All @@ -39,6 +40,9 @@ func NewProc(log *logging.Logger, c Config, args []string) (*Proc, error) {
cmd.Env = env
cmd.Dir = c.WorkDir

cmd.Stdout = stdout
cmd.Stderr = stderr

rpcS, err := New(logging.MustGetLogger(fmt.Sprintf("app_rpc_server_%s", key)),
c.SockFile, key)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/app2/appserver/proc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package appserver

import (
"fmt"
"io"
"os/exec"
"sync"

Expand Down Expand Up @@ -33,12 +34,13 @@ func NewProcManager(log *logging.Logger) *ProcManager {
}

// Run runs the application according to its config and additional args.
func (m *ProcManager) Run(log *logging.Logger, c Config, args []string) (apputil.ProcID, error) {
func (m *ProcManager) Run(log *logging.Logger, c Config, args []string,
stdout, stderr io.Writer) (apputil.ProcID, error) {
if m.Exists(c.Name) {
return 0, errAppAlreadyExists
}

p, err := NewProc(log, c, args)
p, err := NewProc(log, c, args, stdout, stderr)
if err != nil {
return 0, err
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/visor/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,15 @@ func (node *Node) SpawnApp(config *AppConfig, startCh chan<- struct{}) (err erro
}

// TODO: make PackageLogger return *RuleEntry. FieldLogger doesn't expose Writer.
/*logger := node.logger.WithField("_module", fmt.Sprintf("%s.v%s", config.App, config.Version)).Writer()
logger := node.logger.WithField("_module", fmt.Sprintf("%s.v%s", config.App, config.Version)).Writer()
defer func() {
if logErr := logger.Close(); err == nil && logErr != nil {
err = logErr
}
}()

// TODO: pass this guy correctly
cmd.Stdout = logger
cmd.Stderr = logger
*/

pid, err := node.procManager.Run(logging.MustGetLogger(fmt.Sprintf("app_%s", config.App)),
appCfg, append([]string{filepath.Join(node.dir(), config.App)}, config.Args...))
appCfg, append([]string{filepath.Join(node.dir(), config.App)}, config.Args...), logger, logger)
if err != nil {
return fmt.Errorf("error running app %s: %v", config.App, err)
}
Expand Down

0 comments on commit bdaa7b6

Please sign in to comment.