com

package module
v0.0.0-...-140d3bd Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: BSD-3-Clause Imports: 8 Imported by: 4

Documentation

Overview

com - classified output messages | A communication library as addition to fmt and log. The focus is solely to ease manipulation of printing messages to io.Writer's with different purpose (stderr/stdout/files), verbosity levels (from silent to debug) and expressiveness in declaration.

Index

Constants

View Source
const (
	// a special Level - no output at all
	Silent Level = iota
	// Common Level / default
	Common
	// dedicated Levels
	Verbose = 128
	// print all messages with additional info
	Debug = 254
	// print only errors, but all errors
	ErrorsOnly = 255
)
View Source
const (
	D = Debug
	E = ErrorsOnly
	C = Common
	S = Silent
	V = Verbose
)

shortcuts

Variables

View Source
var (
	Stdout      = os.Stdout
	Stderr      = os.Stderr
	PrefixDebug = "[Debug] "
	PrefixError = "[Error] "
)

Default values for Config creation through New()

Functions

This section is empty.

Types

type Config

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

Config behaviour can be manipulated through the global variables before New() call.

func New

func New(setting Level) *Config

New provides a configuration element for printing messages with regard to the set Level.

func (*Config) Custom

func (c *Config) Custom(prefixes, suffixes map[Level]string)

Custom provides a method to add pre-/suffixes.

func (*Config) D

func (c *Config) D() *Config

D is a shortcut for Debug().

func (*Config) Debug

func (c *Config) Debug() *Config

Debug sets the runlevel to Level Debug (255)

func (*Config) E

func (c *Config) E() *Config

E is a shortcut for Err().

func (*Config) Error

func (c *Config) Error() *Config

Err enables a shift to write to c.err / set standard error.

func (*Config) L

func (c *Config) L(runlevel Level) *Config

L is a shortcut for c.Level(runlevel).

func (*Config) Level

func (c *Config) Level(runlevel Level) *Config

Level takes a Level as runlevel to set output situations by the given Level.

func (*Config) LevelIs

func (c *Config) LevelIs() Level

LevelIs returns the current runlevel.

func (*Config) Logger

func (c *Config) Logger(level Level, name string, err bool) *log.Logger

Logger enables you to handle the logged output through the com.Config type. You have to pre-decide if it's handled like an error or normal log value and on which Level.

func (*Config) Print

func (c *Config) Print(msg ...interface{}) (n int, err error)

Print writes to c.out or c.err depending on c.shift, if the given Level is set.

func (*Config) Printf

func (c *Config) Printf(format string, msg ...interface{}) (n int, err error)

Printf formats according to a format specifier and writes to c.out or c.err depending on c.shift, if the given Level is set.

func (*Config) Println

func (c *Config) Println(msg ...interface{}) (n int, err error)

Println writes to c.out or c.err depending on c.shift and appends a newline on msg, if the given Level is set.

func (*Config) TimestampDisable

func (c *Config) TimestampDisable()

TimestampDisable deactivates all timestamps.

func (*Config) TimestampEnable

func (c *Config) TimestampEnable(format string)

TimestampEnable activates timestamps for all output including logging to the format or defaults to "2006-01-02|15:04:05|-0700[MST]|".

func (*Config) V

func (c *Config) V() *Config

V is a shortcut for Verbose().

func (*Config) Verbose

func (c *Config) Verbose() *Config

Verbose sets the runlevel to Level Verbose (128).

type Level

type Level uint8

Level ranges from 0 to 255. A Level always includes all smaller value levels, besides the last two Debug and ErrorsOnly. Debug prints all messages with additional info format. ErrorsOnly prints only error messages and no others.

type Output

type Output func(w io.Writer, format string, msg ...interface{}) (n int, err error)
var DefaultOutput Output = p

Jump to

Keyboard shortcuts

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