output

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: Apache-2.0 Imports: 6 Imported by: 10

Documentation

Overview

Package output handles structured logging for the framework and exploits.

Our goals for logging in go-exploit were something like this:

  • Structured logging for easy parsing (text and JSON).
  • The option to log to the CLI or directly to a file.
  • Program output to stdout, and errors to stderr
  • Different log level controls for the framework and the exploits implementation.

To achieve all of the above, we split the implementation into two logging APIs: exploitlog.go and frameworklog.go. Exploit should use exploitlog.go API such as output.PrintFrameworkSuccess(), output.PrintFrameworkError(), etc. Framework should use frameworklog.go API such as output.PrintFrameworkSuccess(), output.PrintFrameworkError(), etc.

Index

Constants

View Source
const (
	// Extreme debugging that shows executions.
	LevelTrace = slog.Level(-8)
	// Useful tidbits for debugging potential problems.
	LevelDebug = slog.LevelDebug
	// A hihg-level status updat.
	LevelStatus = slog.LevelInfo
	// A non-critical issue that is bubbled up to the user.
	LevelWarning = slog.LevelWarn
	// A special message for outputing software versions.
	LevelVersion = slog.Level(5)
	// An important status message.
	LevelSuccess = slog.Level(6)
	// An important error message.
	LevelError = slog.LevelError
)

Variables

View Source
var FormatJSON = false

FormatJSON indicates if we should use TextHandler or NJSONHandler for logging.

View Source
var LogLevels = map[string]slog.Level{
	"TRACE":   LevelTrace,
	"DEBUG":   LevelDebug,
	"STATUS":  LevelStatus,
	"WARNING": LevelWarning,
	"VERSION": LevelVersion,
	"SUCCESS": LevelSuccess,
	"ERROR":   LevelError,
}

LogLevels is a mapping of the log names to slog level.

Functions

func PrintDebug added in v1.0.16

func PrintDebug(msg string, keys ...any)

PrintDebug logs a string as TRACE If the exploit is not logging to file, this will go to standard error.

func PrintError

func PrintError(msg string, keys ...any)

PrintError logs a string as ERROR If the exploit is not logging to file, this will go to standard error.

func PrintFrameworkDebug added in v1.0.16

func PrintFrameworkDebug(msg string, keys ...any)

PrintFrameworkDebug logs a string as TRACE If the framework is not logging to file, this will go to standard error.

func PrintFrameworkError added in v1.0.16

func PrintFrameworkError(msg string, keys ...any)

PrintFrameworkError logs a string as ERROR If the framework is not logging to file, this will go to standard error.

func PrintFrameworkStatus added in v1.0.16

func PrintFrameworkStatus(msg string, keys ...any)

PrintFrameworkStatus logs a string as STATUS (aka INFO) If the framework is not logging to file, this will go to standard out.

func PrintFrameworkSuccess added in v1.0.16

func PrintFrameworkSuccess(msg string, keys ...any)

PrintFrameworkSuccess logs a string as SUCCESS If the framework is not logging to file, this will go to standard out.

func PrintFrameworkTrace added in v1.0.16

func PrintFrameworkTrace(msg string, keys ...any)

PrintFrameworkTrace logs a string as TRACE If the framework is not logging to file, this will go to standard error.

func PrintFrameworkWarn added in v1.0.16

func PrintFrameworkWarn(msg string, keys ...any)

PrintFrameworkWarn logs a string as WARN If the framework is not logging to file, this will go to standard error.

func PrintShell added in v1.0.16

func PrintShell(msg string)

Displaying content on our fake shell. Need to hold the log mutex for writing to stdout. In theory we could log here too if wanted?

func PrintStatus

func PrintStatus(msg string, keys ...any)

PrintStatus logs a string as STATUS (aka INFO) If the exploit is not logging to file, this will go to standard out.

func PrintSuccess

func PrintSuccess(msg string, keys ...any)

PrintStatus logs a string as SUCCESS If the exploit is not logging to file, this will go to standard out.

func PrintTrace added in v1.0.16

func PrintTrace(msg string, keys ...any)

PrintTrace logs a string as TRACE If the exploit is not logging to file, this will go to standard error.

func PrintVersion added in v1.0.16

func PrintVersion(msg string, host string, port int, version string)

PrintVersion logs a string as VERSION If the exploit is not logging to file, this will go to standard output.

func PrintWarn added in v1.0.16

func PrintWarn(msg string, keys ...any)

PrintWarn logs a string as WARN If the exploit is not logging to file, this will go to standard error.

func PrintfDebug added in v1.0.16

func PrintfDebug(format string, msg ...interface{})

PrintfDebug formats according to a format specifier and logs as DEBUG If the exploit is not logging to file, this will go to standard error.

func PrintfError

func PrintfError(format string, msg ...interface{})

PrintfError formats according to a format specifier and logs as ERROR If the exploit is not logging to file, this will go to standard error.

func PrintfFrameworkDebug added in v1.0.16

func PrintfFrameworkDebug(format string, msg ...interface{})

PrintfFrameworkDebug formats according to a format specifier and logs as DEBUG If the framework is not logging to file, this will go to standard error.

func PrintfFrameworkError added in v1.0.16

func PrintfFrameworkError(format string, msg ...interface{})

PrintfFrameworkError formats according to a format specifier and logs as ERROR If the framework is not logging to file, this will go to standard error.

func PrintfFrameworkStatus added in v1.0.16

func PrintfFrameworkStatus(format string, msg ...interface{})

PrintfFrameworkStatus formats according to a format specifier and logs as STATUS (aka INFO) If the framework is not logging to file, this will go to standard out.

func PrintfFrameworkSuccess added in v1.0.16

func PrintfFrameworkSuccess(format string, msg ...interface{})

PrintfFrameworkSuccess formats according to a format specifier and logs as SUCCESS If the framework is not logging to file, this will go to standard out.

func PrintfFrameworkTrace added in v1.0.16

func PrintfFrameworkTrace(format string, msg ...interface{})

PrintfFrameworkTrace formats according to a format specifier and logs as TRACE If the framework is not logging to file, this will go to standard error.

func PrintfFrameworkWarn added in v1.0.16

func PrintfFrameworkWarn(format string, msg ...interface{})

PrintfFrameworkWarn formats according to a format specifier and logs as WARN If the framework is not logging to file, this will go to standard error.

func PrintfStatus

func PrintfStatus(format string, msg ...interface{})

PrintfStatus formats according to a format specifier and logs as STATUS (aka INFO) If the exploit is not logging to file, this will go to standard out.

func PrintfSuccess

func PrintfSuccess(format string, msg ...interface{})

PrintfSuccess formats according to a format specifier and logs as SUCCESS If the exploit is not logging to file, this will go to standard out.

func PrintfTrace added in v1.0.16

func PrintfTrace(format string, msg ...interface{})

PrintfTrace formats according to a format specifier and logs as TRACE If the exploit is not logging to file, this will go to standard error.

func PrintfWarn added in v1.0.16

func PrintfWarn(format string, msg ...interface{})

PrintfWarn formats according to a format specifier and logs as WARN If the exploit is not logging to file, this will go to standard error.

func SetExploitLogLevel added in v1.0.16

func SetExploitLogLevel(level slog.Level)

Sets the log level for exploit logging. Anything below the provided value will not get logged.

func SetFrameworkLogLevel added in v1.0.16

func SetFrameworkLogLevel(level slog.Level)

Sets the log level for framework logging. Anything below the provided value will not get logged.

func SetOutputFile added in v1.0.16

func SetOutputFile(file string) bool

If logging to a file, function will create/append the file and assign the file as output for all log types.

Types

This section is empty.

Jump to

Keyboard shortcuts

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