Documentation
¶
Overview ¶
msg - Is a library addition to the fmt package and for application output purposes. It enables you to categorize your output as well as modify it by category through prefix and suffix additions on a per Level basis.
Different levels (Common/Verbose/Debug) are set by default and can be extended and customized.
It's exclusive focus is on printing messages to io.Writer's (mainly stdout/stderr).
c := msg.New(msg.V, nil, nil) c.Error().Printf("%v\t\t%v\n", "hello", "world!")
D(), V() and E() are shortcuts for Debug(), Verbose() and Error() Levels respectively.
For comparision:
c := msg.New(msg.Common, nil, nil) c.Println("hello world") fmt.Println("hello world") // equivalent c.E().Println("error world") fmt.Fprintln(os.Stderr, "error world") // equivalent
The greatest strength is to enable or disable verbosity up to debug levels or even shut it down with only one setting at all times.
c.Setting = msg.Debug
All you have to do is pass that returning pointer of New(Level) around to your functions. This enables you to write debug or verbose messages whereever you want.
Index ¶
- Constants
- Variables
- type Config
- func (c *Config) Custom(prefixes, suffixes map[Level]string)
- func (c *Config) D() *Config
- func (c *Config) Debug() *Config
- func (c *Config) E() *Config
- func (c *Config) Error() *Config
- func (c *Config) L(runlevel Level) *Config
- func (c *Config) Level(runlevel Level) *Config
- func (c *Config) Logger(level Level, name string, err bool) *log.Logger
- func (c *Config) Print(msg ...interface{}) (n int, err error)
- func (c *Config) Printf(format string, msg ...interface{}) (n int, err error)
- func (c *Config) Println(msg ...interface{}) (n int, err error)
- func (c *Config) TimestampDisable()
- func (c *Config) TimestampEnable(format string)
- func (c *Config) V() *Config
- func (c *Config) Verbose() *Config
- type Level
- type Output
Constants ¶
const ( // a special Level - no output at all Silent Level = iota // Common Level / default Common // dedicated Levels Verbose = 128 Debug = 254 // print only errors, but all errors ErrorsOnly = 255 )
const ( D = Debug E = ErrorsOnly C = Common S = Silent V = Verbose )
Variables ¶
var ( Stdout = os.Stdout Stderr = os.Stderr PrefixDebug = "[Debug] " PrefixError = "[Error] " )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Setting Level // contains filtered or unexported fields }
func (*Config) Logger ¶
Logger enables you to handle the logged output through the msg.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 ¶
Print writes to c.out or c.err depending on c.shift, if the given Level is set.
func (*Config) Printf ¶
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 ¶
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 ¶
TimestampEnable activates timestamps for all output including logging to the format or defaults to "2006-01-02|15:04:05|-0700[MST]|".