log

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Log

Package log implements leveled logging.

https://pkg.go.dev/github.com/hit9/log

Example

package main

import (
	"github.com/hit9/log"
)

var logger = log.Get("Name")

func main() {
	logger.SetLevel(log.INFO)
	logger.Debug("This is a debug message")
	logger.Info("This is a info message")
	logger.Warn("This is a warning message")
	logger.Error("This is an error message")
	logger.Warn("This is a number %v", 1)
}

License

BSD.

Documentation

Overview

Package log implements a minimal leveled logging library.

Example

var logger = log.Get("ExampleName")

func main() {
	logger.SetLevel(log.INFO)
	logger.Debug("This is a debug message")
	logger.Info("This is a info message")
	logger.Warn("This is a warning message")
	logger.Error("This is an error message")
	logger.Warnf("This is a number %v", 1)
}

Index

Constants

View Source
const (
	DEBUG int = iota
	INFO
	WARN
	ERROR
)

Level

View Source
const (
	DefaultCallerDepth = 2
)

default

Variables

This section is empty.

Functions

func Colored

func Colored(color string, text string) string

Colored returns text in color.

func GetRegistry

func GetRegistry() map[string]*Logger

get log registry

Types

type Logger

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

Logger abstraction.

func Get

func Get(name string) *Logger

New creates a new Logger.

func (*Logger) Debug

func (l *Logger) Debug(format string, a ...interface{}) error

Debug formats and logs message with level DEBUG.

func (*Logger) DisableCallerSourceLogging

func (l *Logger) DisableCallerSourceLogging()

DisableCallerSourceLogging disables the logging for caller source. This sets to true by default.

func (*Logger) Error

func (l *Logger) Error(format string, a ...interface{}) error

Error formats and logs message with level ERROR.

func (*Logger) Fatal

func (l *Logger) Fatal(format string, a ...interface{})

Fatal formats and logs message with level FATAL.

func (*Logger) GetLevel

func (l *Logger) GetLevel() int

GetLevel gets the logging level.

func (*Logger) Info

func (l *Logger) Info(format string, a ...interface{}) error

Info formats and logs message with level INFO.

func (*Logger) Log

func (l *Logger) Log(level int, format string, a ...interface{}) error

func (*Logger) SetCallerDepth

func (l *Logger) SetCallerDepth(callerDepth int)

SetCallerDepth sets the caller depth for this logger.

func (*Logger) SetColored

func (l *Logger) SetColored(b bool)

SetColored sets the color enability.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

SetLevel sets the logging level.

func (*Logger) SetNameLength

func (l *Logger) SetNameLength(n int)

SetNameLength sets the name length.

func (*Logger) SetWriter

func (l *Logger) SetWriter(w io.Writer)

SetWriter sets the writer.

func (*Logger) Smart

func (l *Logger) Smart(e error, format string, a ...interface{})

Smart formats and logs message in different levels according to given error.

func (*Logger) Warn

func (l *Logger) Warn(format string, a ...interface{}) error

Warn formats and logs message with level WARN.

Jump to

Keyboard shortcuts

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