execlog

package
v1.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package execlog handles stdout and stderr pipes of started commands and logs them in JSON using the provided logger

Index

Constants

View Source
const (
	// PipeKey is the key for the pipe the log refers to
	PipeKey = "pipe"
	// StdOut is the PipeKey value for stdout
	StdOut = "stdout"
	// StdErr is the PipeKey value for stderr
	StdErr = "stderr"
)

Variables

This section is empty.

Functions

func RunBuffering

func RunBuffering(cmd *exec.Cmd, cmdName string) (err error)

RunBuffering creates two dedicated pipes for stdout and stderr, run the command and logs its output after the command exited

func RunStreaming

func RunStreaming(cmd *exec.Cmd, cmdName string) (err error)

RunStreaming executes the command redirecting its stdout and stderr to the logger. This function waits for command to terminate end reports non-zero exit codes.

Types

type LogWriter

type LogWriter struct {
	Logger log.Logger
}

LogWriter implements the `Writer` interface using the logger, It uses "Info" as logging level.

func (*LogWriter) Write

func (w *LogWriter) Write(p []byte) (int, error)

Write logs the given slice of bytes using the provided Logger.

type StreamingCmd

type StreamingCmd struct {
	// contains filtered or unexported fields
}

StreamingCmd contains the context of a running streaming command

func RunStreamingNoWait

func RunStreamingNoWait(cmd *exec.Cmd, cmdName string) (streamingCmd *StreamingCmd, err error)

RunStreamingNoWait executes the command redirecting its stdout and stderr to the logger. This function does not wait for command to terminate.

func RunStreamingNoWaitWithWriter

func RunStreamingNoWaitWithWriter(
	cmd *exec.Cmd,
	cmdName string,
	stdoutWriter io.Writer,
	stderrWriter io.Writer,
) (streamingCmd *StreamingCmd, err error)

RunStreamingNoWaitWithWriter executes the command redirecting its stdout and stderr to the corresponding writers. This function does not wait for command to terminate. You can invoke StreamingCmd.Wait() to wait for the command termination and retrieve the exit status.

func StreamingCmdFromProcess

func StreamingCmdFromProcess(process *os.Process) *StreamingCmd

StreamingCmdFromProcess creates a StreamingCmd starting from an existing os.Process. This is useful when we want to adopt a running PostgreSQL instance.

func (*StreamingCmd) Wait

func (se *StreamingCmd) Wait() error

Wait waits for the command to exit and waits for any copying from stdout or stderr to complete.

The returned error is nil if the command runs, has no problems, and exits with a zero exit status.

If the command fails to run or doesn't complete successfully, the error is of type *exec.ExitError. Other error types may be returned for I/O problems.

This implements the same interface of Wait method of exec.Cmd struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL