notify

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 4 Imported by: 5

README

godoc codecov Go Report Card

notify - level managed stdout/stderr notifier

notify is a package for managing outputting various levels of informative notices to STDOUT and STDERR.

Installation

> go get github.com/go-corelibs/notify@latest

Examples

Notifier

func main() {
    notifier := notify.New(notify.Info).Make()
    notifier.Error("this is printed to os.Stderr\n")
    notifier.Info("this is printed to os.Stdout\n")
    // the following Debug call will not output anything becuase the level
    // of the notifier is currently set to Info (which is less than Debug)
    notifier.Debug("this would be printed to os.Stdout\n")
    notifier.ModifyLevel(notify.Debug) // modifying built notifier at runtime
    notifier.Debug("this is printed to os.Stdout\n")
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	// SetLevel modifies the level setting
	SetLevel(level Level) Builder
	// SetOut overrides the default os.Stdout setting
	SetOut(w io.Writer) Builder
	// SetErr overrides the default os.Stderr setting
	SetErr(w io.Writer) Builder
	// Make produces the built Notifier instance
	Make() (n Notifier)
}

Builder is the interface for constructing new Notifier instances

func New

func New(level Level) Builder

New constructs a new Builder instance

type CNotifier

type CNotifier struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*CNotifier) Debug

func (n *CNotifier) Debug(format string, argv ...interface{})

func (*CNotifier) Error

func (n *CNotifier) Error(format string, argv ...interface{})

func (*CNotifier) Info

func (n *CNotifier) Info(format string, argv ...interface{})

func (*CNotifier) Level

func (n *CNotifier) Level() (level Level)

func (*CNotifier) Make

func (n *CNotifier) Make() Notifier

func (*CNotifier) ModifyErr

func (n *CNotifier) ModifyErr(stderr io.Writer) Notifier

func (*CNotifier) ModifyLevel

func (n *CNotifier) ModifyLevel(level Level) Notifier

func (*CNotifier) ModifyOut

func (n *CNotifier) ModifyOut(stdout io.Writer) Notifier

func (*CNotifier) SetErr

func (n *CNotifier) SetErr(w io.Writer) Builder

func (*CNotifier) SetLevel

func (n *CNotifier) SetLevel(level Level) Builder

func (*CNotifier) SetOut

func (n *CNotifier) SetOut(w io.Writer) Builder

func (*CNotifier) Stderr

func (n *CNotifier) Stderr() (w io.Writer)

func (*CNotifier) Stdout

func (n *CNotifier) Stdout() (w io.Writer)

type Level

type Level = int

Level specifies the verbosity of a Notifier

const (
	// Quiet configures the Notifier to produce no output
	Quiet Level = iota
	// Error configures the Notifier to only produce error output
	Error
	// Info configures the Notifier to produce normal and error output
	Info
	// Debug configures the Notifier to produce all outputs
	Debug
)

type Notifier

type Notifier interface {
	// Level returns the verbosity of this Notifier
	Level() (level Level)
	// Stdout returns the io.Writer associated with normal output
	Stdout() (w io.Writer)
	// Stderr returns the io.Writer associated with error output
	Stderr() (w io.Writer)
	// ModifyLevel modifies the configured level setting
	ModifyLevel(level Level) Notifier
	// ModifyOut modifies the configured output writer
	ModifyOut(w io.Writer) Notifier
	// ModifyErr modifies the configured error writer
	ModifyErr(w io.Writer) Notifier
	// Debug passes the arguments to fmt.Fprintf using normal output and only
	// has effect when the Level is set to Debug
	Debug(format string, argv ...interface{})
	// Info passes the arguments to fmt.Fprintf using normal output and only
	// has effect when the Level is set to Info or Debug
	Info(format string, argv ...interface{})
	// Error passes the arguments to fmt.Fprintf using normal output and only
	// has effect when the Level is set to Info or Debug
	Error(format string, argv ...interface{})
}

Jump to

Keyboard shortcuts

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