console

package
v0.0.0-...-dbaf2e2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close for cleaning up.

func Debug

func Debug(format string, v ...interface{})

Debug prints debug level log.

Example
DisableColor()
colorConsole.useTestTime("2021-11-27")
Debug("hello ketty")
Output:

[DEBUG] 2021-11-27 hello ketty

func DisableBorder

func DisableBorder()

DisableBorder prints log with borderless.

Example
DisableBorder()
DisableColor()
colorConsole.useTestTime("2021-11-27")
Info("hello ketty")
Output:

[INFO] 2021-11-27 hello ketty

func DisableColor

func DisableColor()

DisableColor sets the color flag as false, if it is, the Console won't print log with color.

func DisablePrefix

func DisablePrefix()

DisablePrefix prints log without prefix

func Error

func Error(err error)

Error prints error level log.

func ErrorText

func ErrorText(format string, v ...interface{})

ErrorText prints error level log.

Example
DisableColor()
DisablePrefix()
DisableBorder()
ErrorText("hello ketty")
Output:

hello ketty

func Info

func Info(format string, v ...interface{})

Info prints info level log.

Example
DisableColor()
colorConsole.useTestTime("2021-11-27")
Info("hello ketty")
Output:

[INFO] 2021-11-27 hello ketty

func SetOutput

func SetOutput(dir string)

func UsePrefix

func UsePrefix(prefix string)

UsePrefix add a prefix to logger.

Example
c := NewConsole()
c.prefix = "test"
c.DisableBorder()
c.DisableColor()
c.Info("hello ketty")
Output:

test hello ketty

func Warn

func Warn(format string, v ...interface{})

Warn prints warn level log.

Example
DisableColor()
colorConsole.useTestTime("2021-11-27")
Warn("hello ketty")
Output:

[WARN] 2021-11-27 hello ketty

Types

type Console

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

Console is log printer which implements Logger.

func GetConsole

func GetConsole() *Console

GetConsole returns a Console instance.

func NewConsole

func NewConsole(opt ...Option) *Console

NewConsole creates an instance of Console.

func (*Console) Close

func (c *Console) Close()

Close for cleaning up.

func (*Console) Debug

func (c *Console) Debug(format string, v ...interface{})

Debug prints debug level log.

Example
c := NewConsole()
c.DisableColor()
c.useTestTime("2021-11-27")
c.Debug("hello ketty")
Output:

[DEBUG] 2021-11-27┌────────────
[DEBUG] 2021-11-27│  hello ketty
[DEBUG] 2021-11-27└────────────

func (*Console) Disable

func (c *Console) Disable()

Disable prevent log to output.

func (*Console) DisableBorder

func (c *Console) DisableBorder()

DisableBorder prints log with borderless.

Example
c := NewConsole()
c.DisableBorder()
c.DisableColor()
c.useTestTime("2021-11-27")
c.Info("hello ketty")
Output:

[INFO] 2021-11-27 hello ketty

func (*Console) DisableColor

func (c *Console) DisableColor()

DisableColor sets the color flag as false, if it is, the Console won't print log with color.

func (*Console) DisablePrefix

func (c *Console) DisablePrefix()

DisablePrefix prints log without prefix

Example
c := NewConsole()
c.DisableBorder()
c.DisableColor()
c.DisablePrefix()
c.Info("hello ketty")
Output:

hello ketty

func (*Console) Error

func (c *Console) Error(err error)

Error prints error level log.

func (*Console) ErrorText

func (c *Console) ErrorText(format string, v ...interface{})

ErrorText prints error level log.

Example
c := NewConsole()
c.DisableColor()
c.DisablePrefix()
c.DisableBorder()
c.ErrorText("hello ketty")
Output:

hello ketty

func (*Console) Flush

func (c *Console) Flush() error

Flush saves the buffered data on disk file.

func (*Console) Info

func (c *Console) Info(format string, v ...interface{})

Info prints info level log.

Example
c := NewConsole()
c.DisableColor()
c.useTestTime("2021-11-27")
c.Info("hello ketty")
Output:

[INFO] 2021-11-27┌────────────
[INFO] 2021-11-27│  hello ketty
[INFO] 2021-11-27└────────────

func (*Console) SetLevel

func (c *Console) SetLevel(level Level)

SetLevel set log level.

func (*Console) Use

func (c *Console) Use(opt ...Option)

Use sets Option into Console.

func (*Console) Warn

func (c *Console) Warn(format string, v ...interface{})

Warn prints warn level log.

Example
c := NewConsole()
c.DisableColor()
c.useTestTime("2021-11-27")
c.Warn("hello ketty")
Output:

[WARN] 2021-11-27┌────────────
[WARN] 2021-11-27│  hello ketty
[WARN] 2021-11-27└────────────

type Level

type Level int
const (
	LevelDisable Level
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
)

type Option

type Option func(c *Console)

Option is an alias of the function with argument Console.

func WithOutputDir

func WithOutputDir(file string) Option

WithOutputDir sets an output file for Logger.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets a prefix for Logger.

func WithTextOption

func WithTextOption(opt ...text.Option) Option

WithTextOption returns an Option wrapped text.Option.

Jump to

Keyboard shortcuts

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