nfo

package module
v0.0.0-...-1bae4ce Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 18 Imported by: 1

README

nfo

-- import "github.com/cmcoffee/go-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.

var (
	FatalOnOutError    = true // Fatal on Output logging error.
	FatalOnFileError   = true // Fatal on log file or file rotation errors.
	FatalOnExportError = true // Fatal on export/syslog error.

)
var None dummyWriter

False writer for discarding output.

var PleaseWait _loader

PleaseWait is a wait prompt to display between requests.

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 Close
func Close(filename string) (err error)

Closes out a log file.

func Confirm
func Confirm(prompt string) bool

Get confirmation

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.

func DisableExport
func DisableExport(flag int)

Specific which logger to not export.

func DisableOutput
func DisableOutput(flag int)

Disable a specific logger

func EnableExport
func EnableExport(flag int)

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 File
func File(l_file_flag int, filename string, max_size_mb uint, max_rotation uint) (err 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 Flash
func Flash(vars ...interface{})

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

func HideTS
func HideTS()

Hide timestamps in output.

func HookSyslog
func HookSyslog(syslog_writer SyslogWriter)

Send messages to syslog

func Input
func Input(prompt string) string

Gets user input, used during setup and configuration.

func LTZ
func LTZ()

Switches timestamps to local timezone. (Default Setting)

func LocalDefer
func LocalDefer(closer func() error)
func Log
func Log(vars ...interface{})

Log as Info.

func LogFileAppend
func LogFileAppend(existing_logger int, flag int)

Tacks an additional logger to an exising log file.

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 Secret
func Secret(prompt string) string

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

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

Enable a specific logger.

func SetPrefix
func SetPrefix(logger int, prefix_str string)

Change prefix for specified logger.

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

Sets the signals that we listen for.

func SetTimestamp
func SetTimestamp(flag int, use_ts bool)

Enable/Disable Timestamp on output.

func ShowTS
func ShowTS()

Show timestamps. (Default Enabled)

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 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.

Variables

View Source
var (
	FatalOnOutError    = true // Fatal on Output logging error.
	FatalOnFileError   = true // Fatal on log file or file rotation errors.
	FatalOnExportError = true // Fatal on export/syslog error.

)
View Source
var None dummyWriter

False writer for discarding output.

View Source
var PleaseWait _loader

PleaseWait is a wait prompt to display between requests.

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 Close

func Close(filename string) (err error)

Closes out a log file.

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.

func DisableExport

func DisableExport(flag int)

Specific which logger to not export.

func DisableOutput

func DisableOutput(flag int)

Disable a specific logger

func EnableExport

func EnableExport(flag int)

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 File

func File(l_file_flag int, filename string, max_size_mb uint, max_rotation uint) (err 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 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 GetInput

func GetInput(prompt string) string

Gets user input, used during setup and configuration.

func GetSecret

func GetSecret(prompt string) string

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

func HideTS

func HideTS()

Hide timestamps in output.

func HookSyslog

func HookSyslog(syslog_writer SyslogWriter)

Send messages to syslog

func LTZ

func LTZ()

Switches timestamps to local timezone. (Default Setting)

func LocalDefer

func LocalDefer(closer func() error)

This is a way of removing the global defer and instead locally defering to the function.

func Log

func Log(vars ...interface{})

Log as Info.

func LogFileAppend

func LogFileAppend(existing_logger int, flag int)

Tacks an additional logger to an exising log file.

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 int, input io.Writer)

func SetOutput

func SetOutput(flag int, w io.Writer)

Enable a specific logger.

func SetPrefix

func SetPrefix(logger int, prefix_str string)

Change prefix for specified logger.

func SetSignals

func SetSignals(sig ...os.Signal)

Sets the signals that we listen for.

func SetTimestamp

func SetTimestamp(flag int, use_ts bool)

Enable/Disable Timestamp on output.

func ShowTS

func ShowTS()

Show timestamps. (Default Enabled)

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 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