ui

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ui contains basic tools for interacting with a user. This includes generating informational and debugging messages. It also includes functions for controlling whether those messages are displayed or not.

Index

Constants

View Source
const (
	// DefaultTableFormat means use whatever the default is that may have been set
	// by the global option --output-type, etc.
	DefaultTableFormat = "default"

	// TextTableFormat indicates the output format should be human-readable text.
	TextFormat = "text"

	// JSONTableFormat indicates the output format should be machine-readable JSON.
	JSONFormat = "json"

	// JSONIndentedTableFormat indicates JSON output that is indented for readability.
	JSONIndentedFormat = "indented"

	JSONIndentPrefix = ""
	JSONIndentSpacer = "   "

	NoSuchLogger = -1
)

Formatted output types for data more complex than individual messages, such as the format for tabular data output. Choices are "text", "json", "indented", or default which means whatever was set by the command line or profile.

View Source
const (
	AppLogger = iota
	AuthLogger
	ByteCodeLogger
	CLILogger
	CompilerLogger
	DBLogger
	DebugLogger
	InfoLogger
	InternalLogger
	OptimizerLogger
	RestLogger
	ServerLogger
	SQLLogger
	SymbolLogger
	TableLogger
	TraceLogger
	TokenLogger
	UserLogger
)

Classes of loggers go here. These are sequential integer values, and should match the order of the items in the loggers array below.

Variables

View Source
var LogRetainCount = -1

LogRetainCount is the number of roll-over log versions to keep in the logging directory.

View Source
var LogTimeStampFormat string

LogTimeStampFormat stores the format string used to produce log messages, using the Go standard format string. You can override the default by creating a profile item called "ego.log.format".

View Source
var OutputFormat = TextFormat

OutputFormat is the default output format if not overridden by a global option or explicit call from the user.

View Source
var QuietMode = false

QuietMode determines if optional messaging is performed.

Functions

func Active

func Active(class int, mode bool) bool

Active enables or disables a logger.

func ActiveLoggers

func ActiveLoggers() string

Return a comma-separated list of the active loggers.

func CurrentLogFile

func CurrentLogFile() string

Return the path of the current log file being written to.

func IsActive

func IsActive(class int) bool

Determine if a given logger is active. This is particularly useful when deciding if it's worth doing complex formatting operations.

func IsConsolePipe

func IsConsolePipe() bool

IsConsolePipe detects if the console (stdin) is a pipe versus a real device. This is used to manage prompts, etc.

func Log

func Log(class int, format string, args ...interface{})

Log displays a message if the selected log class is enabled. If the class is not active, no action is taken. Use WriteLog if you want to write a message to a logging class regardless of whether it is active or not.

func LoggerByClass

func LoggerByClass(class int) string

Get the name of a given logger class.

func LoggerByName

func LoggerByName(loggerName string) int

For a given logger name, find the class ID.

func LoggerNames

func LoggerNames() []string

func OpenLogFile

func OpenLogFile(userLogFileName string, withTimeStamp bool) error

func Prompt

func Prompt(p string) string

Prompt prints a prompt string, and gets input from the console. The line endings are removed and the remainder of the input is returned as a string.

func PromptPassword

func PromptPassword(p string) string

PromptPassword prompts the user with a string prompt, and then allows the user to enter confidential information such as a password without it being echoed on the terminal. The value entered is returned as a string.

func PurgeLogs

func PurgeLogs() int

func RollOverLog

func RollOverLog()

Roll over the open log. Close the current log, and rename it to include a timestamp of when it was created. Then create a new log file.

func SaveLastLog

func SaveLastLog() error

Save the current (last) log file to the archive name with the timestamp of when the log was initialized.

func Say

func Say(format string, args ...interface{})

Say displays a message to the user unless we are in "quiet" mode. If there are no arguments, the format string is output without further processing (that is, safe even if it contains formatting operators, as long as there are no arguments).

Note that the format string is tested to see if it is probably a localization string. If so, it is localized before output. If it was localized, and there is a single argument that is a proper map[string]interface{} object, then that is used for the formatting.

func Tail

func Tail(count int, session int) []string

func WriteLog

func WriteLog(class int, format string, args ...interface{})

WriteLog displays a message to the log, regardless of whether the logger is enabled. If there is an active log file, the message is added to the log file, else it is written to stdout.

Types

This section is empty.

Jump to

Keyboard shortcuts

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