nfo

package module
v0.0.0-...-99ecaf4 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 18 Imported by: 3

README

nfo

-- import "github.com/cmcoffee/go-snuglib/nfo"

Simple package to get user input from terminal.

Usage

const (
	INFO   = 1 << iota // Log Information
	ERROR              // Log Errors
	WARN               // Log Warning
	NOTICE             // Log Notices
	DEBUG              // Debug Logging
	TRACE              // Trace Logging
	FATAL              // Fatal Logging
	AUX                // Auxilary Log
	AUX2               // Auxilary Log
	AUX3               // Auxilary Log
	AUX4               // Auxilary Log

)
const (
	STD = INFO | ERROR | WARN | NOTICE | FATAL | AUX | AUX2 | AUX3 | AUX4
	ALL = INFO | ERROR | WARN | NOTICE | FATAL | AUX | AUX2 | AUX3 | AUX4 | DEBUG | TRACE
)

Standard Loggers, minus debug and trace.

const (
	LeftToRight = 1 << iota // Display progress bar left to right.
	RightToLeft             // Display progress bar right to left.
	NoRate                  // Do not show transfer rate, left to right.

)
var (
	FatalOnFileError   = true // Fatal on log file or file rotation errors.
	FatalOnExportError = true // Fatal on export/syslog error.
	Animations         = true // Enable/Disable Flash Output

)
var None dummyWriter

False writer for discarding output.

var PleaseWait = new(loading)

PleaseWait is a wait prompt to display between requests.

var ProgressBar = new(progressBar)
func Aux
func Aux(vars ...interface{})

Log as Info, as auxilary output.

func Aux2
func Aux2(vars ...interface{})

Log as Info, as auxilary output.

func Aux3
func Aux3(vars ...interface{})

Log as Info, as auxilary output.

func Aux4
func Aux4(vars ...interface{})

Log as Info, as auxilary output.

func BlockShutdown
func BlockShutdown()

Global wait group, allows running processes to finish up tasks before app shutdown

func Debug
func Debug(vars ...interface{})

Log as Debug.

func Defer
func Defer(closer interface{}) func() error

Adds a function to the global defer, function must take no arguments and either return nothing or return an error. Returns function to be called by local keyword defer if you want to run it now and remove it from global defer.

func DisableExport
func DisableExport(flag uint32)

Specific which logger to not export.

func DrawProgressBar
func DrawProgressBar(sz int, current, max int64, text string) string

Draws a progress bar using sz as the size.

func EnableExport
func EnableExport(flag uint32)

Specify which logs to send to syslog.

func Err
func Err(vars ...interface{})

Log as Error.

func Exit
func Exit(exit_code int)

Intended to be a defer statement at the begining of main, but can be called at anytime with an exit code. Tries to catch a panic if possible and log it as a fatal error, then proceeds to send a signal to the global defer/shutdown handler

func Fatal
func Fatal(vars ...interface{})

Log as Fatal, then quit.

func Flash
func Flash(vars ...interface{})

Don't log, write text to standard error which will be overwritten on the next output.

func GetConfirm
func GetConfirm(prompt string) bool

Get confirmation

func GetFile
func GetFile(flag uint32) io.Writer

Returns log file output.

func GetInput
func GetInput(prompt string) string

Gets user input, used during setup and configuration.

func GetOutput
func GetOutput(flag uint32) io.Writer

Returns log output for text.

func GetSecret
func GetSecret(prompt string) string

Get Hidden/Password input, without returning information to the screen.

func HideTS
func HideTS(flag ...uint32)

Disable Timestamp on output.

func HookSyslog
func HookSyslog(syslog_writer SyslogWriter)

Send messages to syslog

func HumanSize
func HumanSize(bytes int64) string

Provides human readable file sizes.

func Itoa
func Itoa(buf *[]byte, i int, wid int)

Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.

func LTZ
func LTZ()

Switches timestamps to local timezone. (Default Setting)

func Log
func Log(vars ...interface{})

Log as Info.

func LogFile
func LogFile(filename string, max_size_mb uint, max_rotation uint) (io.Writer, error)

Opens a new log file for writing, max_size is threshold for rotation, max_rotation is number of previous logs to hold on to. Set max_size_mb to 0 to disable file rotation.

func NeedAnswer
func NeedAnswer(prompt string, request func(prompt string) string) (output string)

Loop until a non-blank answer is given

func Notice
func Notice(vars ...interface{})

Log as Notice.

func PressEnter
func PressEnter(prompt string)

Prompt to press enter.

func SetFile
func SetFile(flag uint32, input io.Writer)
func SetOutput
func SetOutput(flag uint32, w io.Writer)

Enable a specific logger.

func SetPrefix
func SetPrefix(logger uint32, prefix_str string)

Change prefix for specified logger.

func SetSignals
func SetSignals(sig ...os.Signal)

Sets the signals that we listen for.

func SetTZ
func SetTZ(location string) (err error)
func ShowTS
func ShowTS(flag ...uint32)

Enable Timestamp on output.

func SignalCallback
func SignalCallback(signal os.Signal, callback func() (continue_shutdown bool))

Set a callback function(no arguments) to run after receiving a specific syscall, function returns true to continue shutdown process.

func Stderr
func Stderr(vars ...interface{})

Don't log, just print text to standard error.

func Stdout
func Stdout(vars ...interface{})

Don't log, just print text to standard out.

func Trace
func Trace(vars ...interface{})

Log as Trace.

func UTC
func UTC()

Switches logger to use UTC instead of local timezone.

func UnblockShutdown
func UnblockShutdown()

Task completed, carry on with shutdown.

func UnhookSyslog
func UnhookSyslog()

Disconnect form syslog

func Warn
func Warn(vars ...interface{})

Log as Warn.

type ReadSeekCloser
type ReadSeekCloser interface {
	Seek(offset int64, whence int) (int64, error)
	Read(p []byte) (n int, err error)
	Close() error
}

ReadSeekCloser interface

func TransferCounter
func TransferCounter(input ReadSeekCloser, counter func(int)) ReadSeekCloser

TransferCounter allows you to add a counter callback function to add bytes added during read.

func TransferMonitor
func TransferMonitor(name string, total_size int64, flag int, source ReadSeekCloser) ReadSeekCloser

Add Transfer to transferDisplay. Parameters are "name" displayed for file transfer, "limit_sz" for when to pause transfer (aka between calls/chunks), and "total_sz" the total size of the transfer.

type SyslogWriter
type SyslogWriter interface {
	Alert(string) error
	Crit(string) error
	Debug(string) error
	Emerg(string) error
	Err(string) error
	Info(string) error
	Notice(string) error
	Warning(string) error
}

Interface for log/syslog/Writer.

Documentation

Overview

Simple package to get user input from terminal.

Index

Constants

View Source
const (
	INFO   = 1 << iota // Log Information
	ERROR              // Log Errors
	WARN               // Log Warning
	NOTICE             // Log Notices
	DEBUG              // Debug Logging
	TRACE              // Trace Logging
	FATAL              // Fatal Logging
	AUX                // Auxilary Log
	AUX2               // Auxilary Log
	AUX3               // Auxilary Log
	AUX4               // Auxilary Log

)
View Source
const (
	STD = INFO | ERROR | WARN | NOTICE | FATAL | AUX | AUX2 | AUX3 | AUX4
	ALL = INFO | ERROR | WARN | NOTICE | FATAL | AUX | AUX2 | AUX3 | AUX4 | DEBUG | TRACE
)

Standard Loggers, minus debug and trace.

View Source
const (
	LeftToRight = 1 << iota // Display progress bar left to right.
	RightToLeft             // Display progress bar right to left.
	NoRate                  // Do not show transfer rate, left to right.

)

Variables

View Source
var (
	FatalOnFileError   = true // Fatal on log file or file rotation errors.
	FatalOnExportError = true // Fatal on export/syslog error.
	Animations         = true // Enable/Disable Flash Output

)
View Source
var None dummyWriter

False writer for discarding output.

View Source
var PleaseWait = new(loading)

PleaseWait is a wait prompt to display between requests.

View Source
var ProgressBar = new(progressBar)

Functions

func Aux

func Aux(vars ...interface{})

Log as Info, as auxilary output.

func Aux2

func Aux2(vars ...interface{})

Log as Info, as auxilary output.

func Aux3

func Aux3(vars ...interface{})

Log as Info, as auxilary output.

func Aux4

func Aux4(vars ...interface{})

Log as Info, as auxilary output.

func BlockShutdown

func BlockShutdown()

Global wait group, allows running processes to finish up tasks before app shutdown

func Debug

func Debug(vars ...interface{})

Log as Debug.

func Defer

func Defer(closer interface{}) func() error

Adds a function to the global defer, function must take no arguments and either return nothing or return an error. Returns function to be called by local keyword defer if you want to run it now and remove it from global defer.

func DisableExport

func DisableExport(flag uint32)

Specific which logger to not export.

func DrawProgressBar

func DrawProgressBar(sz int, current, max int64, text string) string

Draws a progress bar using sz as the size.

func EnableExport

func EnableExport(flag uint32)

Specify which logs to send to syslog.

func Err

func Err(vars ...interface{})

Log as Error.

func Exit

func Exit(exit_code int)

Intended to be a defer statement at the begining of main, but can be called at anytime with an exit code. Tries to catch a panic if possible and log it as a fatal error, then proceeds to send a signal to the global defer/shutdown handler

func Fatal

func Fatal(vars ...interface{})

Log as Fatal, then quit.

func Flash

func Flash(vars ...interface{})

Don't log, write text to standard error which will be overwritten on the next output.

func GetConfirm

func GetConfirm(prompt string) bool

Get confirmation

func GetFile

func GetFile(flag uint32) io.Writer

Returns log file output.

func GetInput

func GetInput(prompt string) string

Gets user input, used during setup and configuration.

func GetOutput

func GetOutput(flag uint32) io.Writer

Returns log output for text.

func GetSecret

func GetSecret(prompt string) string

Get Hidden/Password input, without returning information to the screen.

func HideTS

func HideTS(flag ...uint32)

Disable Timestamp on output.

func HookSyslog

func HookSyslog(syslog_writer SyslogWriter)

Send messages to syslog

func HumanSize

func HumanSize(bytes int64) string

Provides human readable file sizes.

func Itoa

func Itoa(buf *[]byte, i int, wid int)

Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.

func LTZ

func LTZ()

Switches timestamps to local timezone. (Default Setting)

func Log

func Log(vars ...interface{})

Log as Info.

func LogFile

func LogFile(filename string, max_size_mb uint, max_rotation uint) (io.Writer, error)

Opens a new log file for writing, max_size is threshold for rotation, max_rotation is number of previous logs to hold on to. Set max_size_mb to 0 to disable file rotation.

func NeedAnswer

func NeedAnswer(prompt string, request func(prompt string) string) (output string)

Loop until a non-blank answer is given

func Notice

func Notice(vars ...interface{})

Log as Notice.

func PressEnter

func PressEnter(prompt string)

Prompt to press enter.

func SetFile

func SetFile(flag uint32, input io.Writer)

func SetOutput

func SetOutput(flag uint32, w io.Writer)

Enable a specific logger.

func SetPrefix

func SetPrefix(logger uint32, prefix_str string)

Change prefix for specified logger.

func SetSignals

func SetSignals(sig ...os.Signal)

Sets the signals that we listen for.

func SetTZ

func SetTZ(location string) (err error)

func ShowTS

func ShowTS(flag ...uint32)

Enable Timestamp on output.

func SignalCallback

func SignalCallback(signal os.Signal, callback func() (continue_shutdown bool))

Set a callback function(no arguments) to run after receiving a specific syscall, function returns true to continue shutdown process.

func Stderr

func Stderr(vars ...interface{})

Don't log, just print text to standard error.

func Stdout

func Stdout(vars ...interface{})

Don't log, just print text to standard out.

func Trace

func Trace(vars ...interface{})

Log as Trace.

func UTC

func UTC()

Switches logger to use UTC instead of local timezone.

func UnblockShutdown

func UnblockShutdown()

Task completed, carry on with shutdown.

func UnhookSyslog

func UnhookSyslog()

Disconnect form syslog

func Warn

func Warn(vars ...interface{})

Log as Warn.

Types

type ReadSeekCloser

type ReadSeekCloser interface {
	Seek(offset int64, whence int) (int64, error)
	Read(p []byte) (n int, err error)
	Close() error
}

ReadSeekCloser interface

func TransferCounter

func TransferCounter(input ReadSeekCloser, counter func(int)) ReadSeekCloser

TransferCounter allows you to add a counter callback function to add bytes added during read.

func TransferMonitor

func TransferMonitor(name string, total_size int64, flag int, source ReadSeekCloser) ReadSeekCloser

Add Transfer to transferDisplay. Parameters are "name" displayed for file transfer, "limit_sz" for when to pause transfer (aka between calls/chunks), and "total_sz" the total size of the transfer.

type SyslogWriter

type SyslogWriter interface {
	Alert(string) error
	Crit(string) error
	Debug(string) error
	Emerg(string) error
	Err(string) error
	Info(string) error
	Notice(string) error
	Warning(string) error
}

Interface for log/syslog/Writer.

Jump to

Keyboard shortcuts

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